• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 532
  • Last Modified:

javascript drop down problem

I my form i have a drop down list after the item get selectem I need to populate the value of the drop down to the text box(text not the value )
 <select spry:repeatchildren="dsProducts" spry:setrow="dsProducts" name="programlist" id="programlist" size="15" onchange="getcurrentvalue();">
      <option spry:if="{ds_RowNumber} == {ds_CurrentRowNumber}"  spry:select="rowSelected" value="{id}" >{categoryname}</option>
       <option spry:if="{ds_RowNumber} != {ds_CurrentRowNumber}" spry:select="rowSelected"  value="{id}">{categoryname}</option>
        </select>
function getcurrentvalue(){
var current = document.getElementById("programlist").value;
document.getElementById("updatecategoryname").value = current;
}

<input type="text" name="updatecategoryname" id="updatecategoryname" value="(Please select the updated category)" size="40">
         
0
erikTsomik
Asked:
erikTsomik
1 Solution
 
discon0Commented:
I'm not sure I understood your question correctly but if you want to make the textbox get the selected text and not the value then you can add this function to your script:

function getCurrentText(){
      var list = document.getElementById("programlist");
      var currentText = list.options[list.selectedIndex].text;
      document.getElementById("updatecategoryname").value = currentText;
}

and change your onchange() event on programlist to use the new function.

<select spry:repeatchildren="dsProducts" spry:setrow="dsProducts" name="programlist" id="programlist" size="15" onchange="getCurrentText();">
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
thsi example does not work
0
 
hieloCommented:
Here is the complete working example. Don't forget to close the problem
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function getcurrentvalue(){
var current = document.getElementById("programlist");
var x = current.selectedIndex;

document.getElementById("updatecategoryname").value = current.options[x].text;
}
</script>
<form>
<div><select spry:repeatchildren="dsProducts" spry:setrow="dsProducts" name="programlist" id="programlist" size="15" onchange="getcurrentvalue();">
      <option spry:if="{ds_RowNumber} == {ds_CurrentRowNumber}"  spry:select="rowSelected" value="{id}" >{categoryname} 1</option>
       <option spry:if="{ds_RowNumber} != {ds_CurrentRowNumber}" spry:select="rowSelected"  value="{id}">{categoryname} 2</option>
        </select></div>
<input type="text" name="updatecategoryname" id="updatecategoryname" value="(Please select the updated category)" size="40">
</form>
</body>
</html>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now