Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2004, 08:19 PM
Authorized User
 
Join Date: Feb 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pass select values to hidden text field?

I know there have to be a million tutorials on this, but I can't seem to find any of them. Using onsubmit, how do I pass the value from a select menu to a hidden text field? Any help would be greatly appreciated.

__________________________________________________ _____________

Confidence is what you feel when you do not truly understand the situation.
__________________
__________________________________________________ _____________

Confidence is what you feel when you do not truly understand the situation.
 
Old July 20th, 2004, 08:48 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Why do you want to do this, if you don't mind me asking?

Anyway, here it is:

<form onsubmit='passSelectValue(this.sel)' [other attributes]>
<select id='sel'>
<option value='one'>one</option>
<option value='two'>two</option>
<option value='three'>three</option>
</select>
<input type='hidden' name='something' id='hiddenField'/>
</form>
<script type='text/javascript'>
function passSelectValues(handle)
{
 document.getElementById('hiddenField').value = handle.options[handle.selectedIndex].value;
}
</script>

If you want to get the text of the selected option instead of the value, use .text instead of .value.

HTH,

Snib

<><
 
Old July 20th, 2004, 09:47 PM
Authorized User
 
Join Date: Feb 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib,

Thank you for taking the time to work on a solution. And I wasn't explaining myself clearly. What I actually wanted was to pass the text value to a hidden field. Sorry about that. What I ended up with is this:

function change_Artist() {
var the_selection = window.document.frmAddItems.mnuSelectArtist;
var the_index = the_selection.selectedIndex;
var the_selected = the_selection.options[the_index].text;
var the_ArtistName = window.document.frmAddItems.txtArtistName.value;
window.document.frmAddItems.txtArtistName.value = the_selected;
    }

...and then calling change_Artist onsubmit. Works nicely - turns out I was getting hung up on syntax errors. It's late...

Thanks again, though.

__________________________________________________ _____________

Confidence is what you feel when you do not truly understand the situation.





Similar Threads
Thread Thread Starter Forum Replies Last Post
pass value to the hidden field Dejitan ASP.NET 1.0 and 1.1 Basics 4 December 21st, 2006 03:13 AM
Pass hidden value from one domain to another relaytest49 Classic ASP Professional 6 October 31st, 2006 12:29 PM
Hidden field ashoka_klt ASP.NET 1.0 and 1.1 Basics 1 September 6th, 2006 07:12 AM
show/hide text field from select (drop down) Gotaka4 Javascript 6 December 7th, 2005 05:44 AM
pass hidden values X-Ken VS.NET 2002/2003 2 September 8th, 2004 07:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.