| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Registered User
|
copy drop down value to text box
I've lokked high and low for a script to sort this out... Basically I need a function that can be called upon by clicking a check box. The function should copy the current value of a drop down menu and transfer it into a checkbox... Does that make sense? I've already used a function to transfer values from textbox to text box. function copy() { document.form1.CC_Address.value = document.form1.Address.value ; } However I can't manage to make this work for dropdown menus to text box. Anyone??? |
|
|
|
|
|
#2 (permalink) |
|
Zły
|
<script language="javascript" type="text/javascript"> function fillcheckbox(selection) { document.form1.mycheckbox.value = selection.value; } </script> <select name="combo" onchange="fillcheckbox(this);"> ..... </select> <input type="checkbox" name="mycheckbox" value="zero"> .... Remember that the value of the checkbox will only be passed to the form's action page when the checkbox is selected. |
|
|
|
#4 (permalink) |
|
trouble free and loverlee
Join Date: Mar 2003
Location: YooKay
Posts: 2,901
|
e.g. Code:
Change id and function names to suit. |
|
|
|
#8 (permalink) | |
|
trouble free and loverlee
Join Date: Mar 2003
Location: YooKay
Posts: 2,901
|
Quote:
You might wanna add checker so that the function is only triggered when the checkbox is actually checked. e.g. Code:
It's also an idea to add in some else code that clears the second set of input fields if the checkbox is then unchecked. |
|
|
|
|
#9 (permalink) |
|
Registered User
|
Still not working
This didn't work in the end... document.form1.mytextbox.value = document.form1.combobox.value; No error messages show up but value is passed. My chance I tried document.form1.mytextbox.value = document.form1.combobox.selected; and it worked. Cheers for the help anyway. Mark |
|
|
|
#13 (permalink) |
|
Registered User
Join Date: Mar 2004
Location: Derby, UK
Posts: 24
|
combobox.value is not supported cross-browser afaik, you should get the value of the currently selected option instead, using combobox.options[combobox.selectedIndex].value instead, remembering to check that combobox.selectedIndex is > -1 first, otherwise no option is selected. HTH, Dai |
|
![]() |