Old 15-06-2004, 15:34   #1 (permalink)
markdregan
Registered User
 
Join Date: Jun 2004
Location: Dublin
Posts: 45
Send a message via AIM to markdregan Send a message via Skype™ to markdregan
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???
  Reply With Quote
Old 15-06-2004, 17:23   #2 (permalink)
adras
Zły
 
adras's Avatar
 
Join Date: May 2004
Location: Toronto, Canada
Posts: 1,898
Send a message via MSN to adras
<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.
__________________
  Reply With Quote
Old 16-06-2004, 08:54   #3 (permalink)
markdregan
Registered User
 
Join Date: Jun 2004
Location: Dublin
Posts: 45
Send a message via AIM to markdregan Send a message via Skype™ to markdregan
Nearly

Not quite. I wanted the value from the dropdown to be passed to a text box...
  Reply With Quote
Old 16-06-2004, 09:18   #4 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,901
e.g.
Code:
function doThis() { if (document.forms.myform.mycheckbox.checked == true) { document.forms.myform.mytextfield.value = document.forms.myform.myselection.value; } } … <select id="myselection" onchange="doThis()"> … </select>

Change id and function names to suit.
  Reply With Quote
Old 16-06-2004, 11:30   #5 (permalink)
adras
Zły
 
adras's Avatar
 
Join Date: May 2004
Location: Toronto, Canada
Posts: 1,898
Send a message via MSN to adras
You want the value from the drop down passed onto to a textbox when you click on a checkbox?

Well in you fist post you said that you want a value from a combobox passed on to a checkbox...

which one is it?
__________________
  Reply With Quote
Old 17-06-2004, 05:09   #6 (permalink)
markdregan
Registered User
 
Join Date: Jun 2004
Location: Dublin
Posts: 45
Send a message via AIM to markdregan Send a message via Skype™ to markdregan
Re:

  Reply With Quote
Old 17-06-2004, 11:00   #7 (permalink)
adras
Zły
 
adras's Avatar
 
Join Date: May 2004
Location: Toronto, Canada
Posts: 1,898
Send a message via MSN to adras
function populateTextBoxes()
{
document.form1.mytextbox.value = document.form1.combobox.value;
}

and call this inside the checkbox input tag - with an onchange event.
__________________
  Reply With Quote
Old 17-06-2004, 11:59   #8 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,901
Quote:
Originally Posted by adras
function populateTextBoxes() {
document.form1.mytextbox.value = document.form1.combobox.value;
}

and call this inside the checkbox input tag - with an onchange event.

You might wanna add checker so that the function is only triggered when the checkbox is actually checked.
e.g.
Code:
function populateTextBoxes() { if (document.forms.form1.checkbox.checked == true) { document.form1.mytextbox.value = document.form1.combobox.value; } }

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.
  Reply With Quote
Old 18-06-2004, 09:11   #9 (permalink)
markdregan
Registered User
 
Join Date: Jun 2004
Location: Dublin
Posts: 45
Send a message via AIM to markdregan Send a message via Skype™ to markdregan
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
  Reply With Quote
Old 18-06-2004, 09:12   #10 (permalink)
markdregan
Registered User
 
Join Date: Jun 2004
Location: Dublin
Posts: 45
Send a message via AIM to markdregan Send a message via Skype™ to markdregan
?

My chance = By chance
  Reply With Quote
Old 18-06-2004, 10:09   #11 (permalink)
markdregan
Registered User
 
Join Date: Jun 2004
Location: Dublin
Posts: 45
Send a message via AIM to markdregan Send a message via Skype™ to markdregan
??????

I'm completly wrong.

My changes didn't actually work.

The script given by you worked after all. Wrong side of the bed of something!!!
  Reply With Quote
Old 18-06-2004, 10:20   #12 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,901
All's well…
  Reply With Quote
Old 30-06-2004, 07:03   #13 (permalink)
DaiWelsh
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
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8