Asked By
Shaider
0 points
N/A
Posted on - 07/14/2011
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.
Answered By
brzbee
5 points
N/A
#82698
Help with dropdown menus in JavaScript!
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">
Help with dropdown menus in JavaScript!
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;
|
Â