Click to See Complete Forum and Search --> : Change a field value upon submit?


briandunning
05-27-2003, 06:25 PM
Is there any way to use an onClick to change the value of a field depending upon which of two submit buttons is clicked, like this:

<input type="text" name="myField" value="red">

<input type="submit" value="Change it to Blue" onClick="??">

<input type="submit" value="Change it to Yellow" onClick="??">

Thanks,

Charles
05-27-2003, 06:34 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<form action="" onsubmit="return false">
<p><input type="text" name="color"></p>
<p><input type="submit" value="Blue" onclick="this.form.color.value='Blue'">
<input type="submit" value="Red" onclick="this.form.color.value='Red'"></p>
</form>
<p>Note: This will fail one in ten times.</p>

khalidali63
05-27-2003, 06:36 PM
I am sure you have your reasons for having 2 submit buttons in the form..:D

here is the solution anyways.

<input type="text" name="myField" value="red">
<input type="submit" value="Change it to Blue" onClick="this.form.myField.value=this.value">
<input type="submit" value="Change it to Yellow" onClick="this.form.myField.value=this.value">