Skip to main content
Participant
May 30, 2006
Answered

Using OnChange or OnBlur to changes the value of a hidden field

  • May 30, 2006
  • 1 reply
  • 1333 views
I have a need to update the value of a hidden field with the value of a list menu. I researched the OnBlur and OnChange JavaScript functions but did not find anything suitable. Here's the deal:

If a user selects California from a State list menu, I need to immediately update the the value of a hidden field with 'California' . (Both fields are on the same page) All of this has to happen BEFORE the user Submits the page. Anytime they select the state from the list menu the hidden field value has to change.

Can anyone offer any suggestions?

Thank you!
This topic has been closed for replies.
Correct answer PA7211987
Yep, that did the trick for the hidden field. Many thanks.

Will I be able to also store that value into a session variable? (see previous post)

1 reply

Inspiring
May 30, 2006
Here you go...let us know if this is what you wanted.


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<script language=javascript>
function copydafields(){
document.daform.text2.value=document.daform.text1.value
return true
}
</script>
<form action="" method="post" name="daform" id="daform">
<p>Master:
<input name="text1" type="text" id="text1"
onBlur="copydafields(this.form)">
</p>
<p>Hidden:
<input name="text2" type="text" id="text2">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>



"PA" <webforumsuser@macromedia.com> wrote in message
news:e5ibjh$f45$1@forums.macromedia.com...
>I have a need to update the value of a hidden field with the value of a
>list
> menu. I researched the OnBlur and OnChange JavaScript functions but did
> not
> find anything suitable. Here's the deal:
>
> If a user selects California from a State list menu, I need to immediately
> update the the value of a hidden field with 'California' . (Both fields
> are on
> the same page) All of this has to happen BEFORE the user Submits the
> page.
> Anytime they select the state from the list menu the hidden field value
> has to
> change.
>
> Can anyone offer any suggestions?
>
> Thank you!
>
>


PA7211987Author
Participant
May 30, 2006
That looks like it may work! I'll check it out and get back to you. Thanks for the quick response.

If I change the field type of Field2 to Hidden, I should get the same results, right?

As long as I'm here: I may also need to store the selected value as an ASP Session Variable. (In addition to, or as an alternative to the hidden field) Is this possible?

Thanks again!
PA7211987AuthorCorrect answer
Participant
May 30, 2006
Yep, that did the trick for the hidden field. Many thanks.

Will I be able to also store that value into a session variable? (see previous post)