Jump to content

Appending an input field froma dropdown?


Solarpitch

Recommended Posts

Hey,

 

Just wondering how I can achieve this as my JS skills arn't that great. I have a drop down with 10 values from 1 - 10. If the user selects 3 from the dropdown I want to append 3 textfields below it.. if they choose 5 .. it appends 5 textfields and so on. I'm trying to achieve this with JQuery but not having much luck.

Link to comment
https://forums.phpfreaks.com/topic/196876-appending-an-input-field-froma-dropdown/
Share on other sites

<script language="javascript">
function makeBoxes(){
var divElement=document.getElementById("dynamicText")
var textHTML="";
var element=document.getElementById("selectBox")
for (var i=0; i<element.options.length; i++){
if (element.options[i].selected==true){
textHTML=textHTML+"<input type='textbox' Name='"+i+"' Id='"+i+"'>"
}
}
divElement.innerHTML=textHTML;
}

</script>


<form name="testform">
<select multiple id="selectBox" size="2" width="100" onClick="javascript:makeBoxes()">
<option value="first">first
<option value="second">second
<option value="third">third
<option value="fourth">fourth
<option value="fifth">fifth
<option value="sixth">sixth
</select>
<div id="dynamicText"></div>
</form>

 

I like the way you think      :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.