Results 1 to 6 of 6

Thread: Please Help - Simple Form Dropdown that Opens a Text input

  1. #1
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Please Help - Simple Form Dropdown that Opens a Text input

    Hey everyone. Been racking my brain all day trying to figure out how to duplicate this code with the limited javascript knowledge I have been trying to learn.

    This code is a Dropdown menu of Yes or No, than a Select button that Opens up a Text Input directly below the dropdown. So far, It works great. My problem is I need at least two of these on the same page and I do not know how to go about it. I have tried changing values to accommodate adding another on the same form, but than both stop working. Can someone Please HELP!

    Thank you in advance.

    Code:
    <html>
    <head>
    <SCRIPT language="javascript">
    function add(type) {
     
        //Create an input type dynamically.
        var element = document.createElement("input");
     
        //Assign different attributes to the element.
        element.setAttribute("type", type);
        element.setAttribute("value", type);
        element.setAttribute("name", type);
        element.setAttribute("id", type);
     
        var foo = document.getElementById("fooBar");
     
        //Append the element in page (in span).
        foo.appendChild(element);
     
    }
    </SCRIPT>
    </head>
     
    <body>
    <label>
    <SELECT name="element">
    <OPTION value="text" name="refer_yes" id="refer_yes">Yes</OPTION>
    <OPTION value="text" name="refer_no" id="refer_no">No</OPTION>
    </SELECT>
    
    <INPUT type="button" value="Select" onclick="add(document.forms[0].element.value='')"/>
    </label>
    <span id="fooBar">&nbsp;</span>
    </body>
    <html>
    Last edited by leblanc; 12-23-2010 at 01:00 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Your code does not work at all for me.
    Jeremy | jfein.net

  3. #3
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Yeah, That code is garbage. I am abandoning that style and going with a display: hide. Sorry.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Is this thread resolved then?
    Jeremy | jfein.net

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

    leblanc (12-23-2010)

  6. #5
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Yes. Thank you responding to my question btw. I appreciate it much.

  7. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No problem, I'm glad to help

    Here on DD, we like to keep things organized. In an effort to do so, you have the option to set a thread to resolved when an issue is fixed. To make the status of the thread resolved:
    1. Go to your first post
    2. Edit your first post
    3. Click "Go Advanced"
    4. In the dropdown next to the title, select "RESOLVED"
    Jeremy | jfein.net

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
  •