Results 1 to 4 of 4

Thread: How Do I Make My Form Work

  1. #1
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question How Do I Make My Form Work

    This is what I have done. Now my question is that I have the friend one working but cannot get a repeat with another question which has another question and has a second box that needs to come up. How do i achieve this.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <head>
    <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--

    function SelectCng(sel,id){
    document.getElementById(id).style.display=sel.selectedIndex==3?'':'none';
    }
    //-->
    </script></head>

    <body>
    <form>
    <table border="1">
    <tr>
    <td>Your Name </td><td><input type="text" name="Name" /></td></tr>
    <tr>
    <td>Email Address</td><td><input type="text" name="Email" /></td></tr>
    <tr>
    <td>First Time Here?</td><td><select size="1" name="First">
    <option value="No">No</option>
    <option value="Yes">Yes</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>
    How did you find us?
    </td>
    <td>
    <select size="1" name="Found_by" onchange="SelectCng(this,'Friend');" >
    <option value="Newspaper">Newspaper</option>
    <option value="Search Engine">Search Engine</option>
    <option value="Flyer">Flyer</option>
    <option value="Friend">Friend</option>
    </select>
    </td>
    </tr>
    <tr id="Friend" style="display:none;" >
    <td>
    Friends Name
    </td>
    <td>
    <input name="FriendName">
    </td>
    </tr>
    </form>
    </table>

    </body>

    </html>

  2. #2
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    I must admit this is a tough situation to describe, but please use a more descriptive title next time - e.g. Doubling this DOM Modification.

    EDIT: BTW, your <form> and <table> tags are out of order; the form opens before the table and closes before the table. I prefer the form on the outside, personally.

    Anyway, note that all I did was copy the rows and change the IDs to keep them unique.
    Code:
    <tr>
    <td>
    How did you find us?
    </td>
    <td>
    <select size="1" name="Found_by" onchange="SelectCng(this,'Friend1');" >
    <option value="Newspaper">Newspaper</option>
    <option value="Search Engine">Search Engine</option>
    <option value="Flyer">Flyer</option>
    <option value="Friend">Friend</option>
    </select>
    </td>
    </tr>
    <tr id="Friend1" style="display:none;" >
    <td>
    First Friend's Name
    </td>
    <td>
    <input name="FriendName">
    </td>
    </tr>
    <tr>
    <td>
    How did you find us?
    </td>
    <td>
    <select size="1" name="Found_by" onchange="SelectCng(this,'Friend2');" >
    <option value="Newspaper">Newspaper</option>
    <option value="Search Engine">Search Engine</option>
    <option value="Flyer">Flyer</option>
    <option value="Friend">Friend</option>
    </select>
    </td>
    </tr>
    <tr id="Friend2" style="display:none;" >
    <td>
    Second Friend's Name
    </td>
    <td>
    <input name="FriendName">
    </td>
    </tr>
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  3. #3
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks.

    I tried doing that but Friend number 2 does show on my drop down list. What shows up is

    Search Engine
    Newspaper
    Flyer
    Friend (and a box shows if selected)

    I want it to show as follows
    Search Engine
    Newspaper
    Flyer
    Friend (box shows for text input if selected, otherwise it is hidden)
    Friend #2 (box shows for text input if selected, otherwise it is hidden)

  4. #4
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    You should have been clearer about what you wanted in the first place. Also, please study this to understand my changes, and ask any questions about it.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
    <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function SelectCng(sel,ids){
        for(index in ids){
            document.getElementById(ids[index][1]).style.display =
                    sel.selectedIndex == ids[index][0] ? '' : 'none';
        }
    }
    //-->
    </script></head>
    
    <body>
    <form>
    <table border="1">
    <tr>
    <td>Your Name </td><td><input type="text" name="Name" /></td></tr>
    <tr>
    <td>Email Address</td><td><input type="text" name="Email" /></td></tr>
    <tr>
    <td>First Time Here?</td><td><select size="1" name="First">
    <option value="No">No</option>
    <option value="Yes">Yes</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>
    How did you find us?
    </td>
    <td>
    <select size="1" name="Found_by" onchange="SelectCng(this,[[3, 'Friend1'], [4, 'Friend2']]);" >
    <option value="Newspaper">Newspaper</option>
    <option value="Search Engine">Search Engine</option>
    <option value="Flyer">Flyer</option>
    <option value="Friend">Friend</option>
    <option value="Friend">Friend</option>
    </select>
    </td>
    </tr>
    <tr id="Friend1" style="display:none;" >
    <td>
    Friends Name
    </td>
    <td>
    <input name="FriendName1">
    </td>
    </tr>
    </tr>
    <tr id="Friend2" style="display:none;" >
    <td>
    Friends Name
    </td>
    <td>
    <input name="FriendName2">
    </td>
    </tr>
    </table>
    </form>
    
    </body>
    
    </html>
    Last edited by Jesdisciple; 08-04-2008 at 05:23 PM.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  5. The Following User Says Thank You to Jesdisciple For This Useful Post:

    bigkga (08-04-2008)

Bookmarks

Posting Permissions

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