Results 1 to 8 of 8

Thread: Ajaxy form

  1. #1
    Join Date
    Dec 2006
    Posts
    76

    Ajaxy form

    I am making a form using PHP. I was wondering if there was a way to make it so that when a user clicks on a button, more fields appear. For example, if anyone uses GMail, when you attach an attachment, you could click on add another one, and another field appears.

    Thank you

  2. #2
    Join Date
    Nov 2002
    Location
    United Kingdom
    Posts
    247
    you would want to use javascript for this.
    Check out document.write and innerHTML. Or you could use PHP but it would invlove the pageg being refreshed.

  3. #3
    Join Date
    Dec 2006
    Posts
    76
    Quote Originally Posted by X-TechMedia
    you would want to use javascript for this.
    Check out document.write and innerHTML. Or you could use PHP but it would invlove the pageg being refreshed.
    I was aware that it had to be in javascript. I was wondering if anyone actually knew how to do it.

  4. #4
    Join Date
    May 2004
    Location
    Lansing, MI, USA
    Posts
    1,548
    Quote Originally Posted by computerwiz3491
    I was aware that it had to be in javascript. I was wondering if anyone actually knew how to do it.
    The key in the idea is using id's and blank areas and such... a simple example would be like so:

    This goes in your <head> tags...
    Code:
    <script type="text/javascript">
    //<!--
      function setInfoBlock(myText) {
        document.getElementById('infoBlock').innerHTML = myText;
      }
    //-->
    </script>
    Then somewhere in the document:

    Code:
    <input type="button" onclick="setInfoBlock('hello!');" value="Set Hello!" />
    <input type="button" onclick="setInfoBlock('Hiya!');" value="Set Hiya!" />
    <div id="infoBlock">Click a Button Above to Change Me!</div>
    Jacob - WebOnce Technologies - 30 Day 100% Satisfaction Guarantee - Over 5 Years Going Strong!
    Website Hosting, PHP4&5, RoR, MySQL 5.0, Reseller Hosting, Development, and Designs
    Powered By JAM - Professional Website Development - PHP, MySQL, JavaScript, AJAX - Projects Small & Large

  5. #5
    Join Date
    Dec 2006
    Posts
    76
    Quote Originally Posted by WO-Jacob
    The key in the idea is using id's and blank areas and such... a simple example would be like so:

    This goes in your <head> tags...
    Code:
    <script type="text/javascript">
    //<!--
      function setInfoBlock(myText) {
        document.getElementById('infoBlock').innerHTML = myText;
      }
    //-->
    </script>
    Then somewhere in the document:

    Code:
    <input type="button" onclick="setInfoBlock('hello!');" value="Set Hello!" />
    <input type="button" onclick="setInfoBlock('Hiya!');" value="Set Hiya!" />
    <div id="infoBlock">Click a Button Above to Change Me!</div>

    I don't think that this is what i meant. I'm sorry if I wasn't clear.

    Let's say that I have a form that accepts user data, and I want to be able to collect multiple phone numbers. So I have a a form, but next to the field for phone number, there is a button that says "Add More" and when the user clicks it, a new field appears, so that they could enter another phone number, and they could do this for evey phone number they want to add. I tried using a document.write and an onclick to display another field, but it only works once. If I try adding another field it says that the variable isn't defined.

    Thank you in advance.

  6. #6
    Join Date
    May 2004
    Location
    Lansing, MI, USA
    Posts
    1,548
    Quote Originally Posted by computerwiz3491
    I don't think that this is what i meant. I'm sorry if I wasn't clear.

    Let's say that I have a form that accepts user data, and I want to be able to collect multiple phone numbers. So I have a a form, but next to the field for phone number, there is a button that says "Add More" and when the user clicks it, a new field appears, so that they could enter another phone number, and they could do this for evey phone number they want to add. I tried using a document.write and an onclick to display another field, but it only works once. If I try adding another field it says that the variable isn't defined.

    Thank you in advance.
    Ah, it's simple enough, but I dunno if you're going to get anyone to do it for you for free ...

    The example I gave you should get you well on your way to it, with a little creative thinking, though.
    Jacob - WebOnce Technologies - 30 Day 100% Satisfaction Guarantee - Over 5 Years Going Strong!
    Website Hosting, PHP4&5, RoR, MySQL 5.0, Reseller Hosting, Development, and Designs
    Powered By JAM - Professional Website Development - PHP, MySQL, JavaScript, AJAX - Projects Small & Large

  7. #7
    Join Date
    Dec 2006
    Posts
    76
    Quote Originally Posted by WO-Jacob
    Ah, it's simple enough, but I dunno if you're going to get anyone to do it for you for free ...

    The example I gave you should get you well on your way to it, with a little creative thinking, though.
    Thank you, I think I got it now, I'll post back later if my idea works.

  8. #8
    Join Date
    Dec 2006
    Posts
    76
    Quote Originally Posted by computerwiz3491
    Thank you, I think I got it now, I'll post back later if my idea works.
    My idea didn't work. It was to substitute a pull-down menu for the buttons in the other script. The value would then be the field i wanted to show. This works at first, but you can't have more than 1 field, so it kindof defeats the point. The problem is that you can't put "<" or ">" inside of a form element (or any html element) and if you use the &lt; or &rt; equivlency, it doens't display a form field because it thinks that it's standard text.

    Does anyone have any other ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •