Hi,
I like to add textbox based on the user selection in drop down box,I have used an function to do that but its not workin,also i like to append the selected value(from drop down) to the input from the text box.

Cheers!
lpk

Recommended Answers

Please show your code first

Jump to Post

this is what you are looking for , i guess

<html>
<head>
</head>
<script type="text/javascript">
function showdv(obj,id1,id2)
{

txt=obj.options[obj.selectedIndex].text; 
document.getElementById("box").style.display='none';

if(txt.match(id1))
{
document.getElementById("box").style.display='block';
document.getElementById("boxx").value=txt
}

if(txt.match(id2))
{
document.getElementById("box").style.display='block';
document.getElementById("boxx").value=txt
}


}
</script>

<body>

<thead>
<select id="opts" onchange="showdv(this,'one','two');" >
<option value="">select</option>
<option value="one">one</option>
<option value="two">two</option>
</select>
</thead>

<div …
Jump to Post

All 6 Replies

Please show your code first

HTML code:

<td><select name=select1 id="Expertise" name="Expertise" onChange=checkForm(document.form1.select1)> 
            	<option>Trained</option>
            	<option>ProjectExp</option>
            	<option>Certified</option>
            	<option>ProjectExp & Certified</option></select>
            	</td>

SCRIPT:

function checkForm(type) {      
     var a=type.selectedIndex
    if(a==1)
{//code to add text fields
}
  
}

this is what you are looking for , i guess

<html>
<head>
</head>
<script type="text/javascript">
function showdv(obj,id1,id2)
{

txt=obj.options[obj.selectedIndex].text; 
document.getElementById("box").style.display='none';

if(txt.match(id1))
{
document.getElementById("box").style.display='block';
document.getElementById("boxx").value=txt
}

if(txt.match(id2))
{
document.getElementById("box").style.display='block';
document.getElementById("boxx").value=txt
}


}
</script>

<body>

<thead>
<select id="opts" onchange="showdv(this,'one','two');" >
<option value="">select</option>
<option value="one">one</option>
<option value="two">two</option>
</select>
</thead>

<div id="box" style="display:none;">			
<input Type="text" id="boxx"  maxlength="20" >
</div>

</body>
</html>

hope it helps...

Hi ayesha,
The code you have given works great..But when i make some changes,i got struck with it...
Actually i will be having multiple drop down boxes(no's decided dynamcially)when i select 1 and 2 a text should appear near to the drop down..

Can you help me out in this...

@prasannakarthik
can we see the code ayesha gave you ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.