Help with dropdown menus in JavaScript!

Asked By 0 points N/A Posted on -
qa-featured

I recently got a problem with my JavaScript. I couldn't get the value of the dropdown boxes if the value is one of the alphabet letters. How do I get the value of dropdown boxes and output it into a text box. I tried to get the value directly but it only works with a message box.

SHARE
Best Answer by brzbee
Best Answer
Best Answer
Answered By 5 points N/A #82698

Help with dropdown menus in JavaScript!

qa-featured

Hi!

To get the selected item from your dropdown box :

document.getElementById("dropdownlistname").value;

To catch the value of the selected item to the textbox:

document.getElementById("txtboxname").value = document.getElementById("dropdownlistname").value;

Will share to you my sample code:
 
<script type="text/JavaScript">
function getValue(){
document.getElementById("txtboxname").value = document.getElementById("dropdownlistname").value;
}</script>
 
<select name="dropdownlistname" id="dropdownlistname" onchange="getValue()">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
 
<input type="text" name="txtboxname" id="txtboxname">
Answered By 0 points N/A #82699

Help with dropdown menus in JavaScript!

qa-featured

Good day,

Here is a script that can solve your problem. Just follow the data inside the image.

Insert the codes in the heads per heads as tags.

// Copyright 2006-2007 javascript-array.com

 

vartimeout = 500;

varclosetimer = 0;

varddmenuitem = 0;

 

// open hidden layer

functionmopen(id)

{

// cancel close timer

mcancelclosetime();

 

// close old layer

if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

 

// get new layer and show it

ddmenuitem = document.getElementById(id);

ddmenuitem.style.visibility = 'visible';

 

 }

// close showed layer

functionmclose()

{

if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

}

 

// go close timer

functionmclosetime()

{

closetimer = window.setTimeout(mclose, timeout);

}

 

// cancel close timer

functionmcancelclosetime()

{

if(closetimer)

{

window.clearTimeout(closetimer);

closetimer = null;

}

}

 

// close layer when click-out

document.onclick = mclose;

 

Related Questions