PDA

View Full Version : handle combo box with JavaScript



sfchun
06-17-2008, 01:53 AM
Hi ,

i got a very simple problem (at least i gues it is)...

I have a html combobox in a form, and i would like to handle the selected option with a javascript function.
My problem seems to be : how can i get the selected option with javascript ...
not sure ...

Here is my error message (got with firebug) :
document.frmname have no properties

My code :


<script type="text/javascript">
<!--
function getit(comboboxname){
SelectedDownload=document.frmname.getElementById(comboboxname).value;
alert(SelectedDownload); /* debug */
}
-->
</script>
<form name="MyDownloads">
<select name="MyDownloadItems" id="MyDownloadItems" size="1" style="background-color:#5aff52;">
<option value="download1.zip">Download 1</option>
<option value="download2.zip">Download 2</option>
<option value="download3.zip">Download 3</option>
</select>
<input type="button" name="Download" value="Download" onclick="getit('MyDownloadItems');">
</form>

rangana
06-17-2008, 03:02 AM
See if removing the highlighted helps:


SelectedDownload=document.frmname.getElementById(comboboxname).value;

sfchun
06-17-2008, 04:34 AM
works great , thanks !
I was thinking too much complicate... :p