View Full Version : Resolved Please Help - Simple Form Dropdown that Opens a Text input

12-22-2010, 11:57 PM
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.

<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).


<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>

<INPUT type="button" value="Select" onclick="add(document.forms[0].element.value='')"/>
<span id="fooBar">&nbsp;</span>

12-23-2010, 12:09 AM
Your code does not work at all for me.

12-23-2010, 12:29 AM
Yeah, That code is garbage. I am abandoning that style and going with a display: hide. Sorry.

12-23-2010, 12:35 AM
Is this thread resolved then?

12-23-2010, 12:45 AM
Yes. Thank you responding to my question btw. I appreciate it much.

12-23-2010, 12:55 AM
No problem, I'm glad to help :D

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"