PDA

View Full Version : why isnt this submiting my form


Bluemonkey
10-20-2002, 10:17 AM
this is my code and all it does is asign a value to the hidden input but does not submit the form

<form name="imageselect" method="post" action="step_two.asp">

<a href="#" onClick="boatbut()"><img src="boat.jpg" width="100" height="142" border="0"></a>

<input type="hidden" id="hiddenval" name="hiddenval" value="">

</form>
<script language="JavaScript">

function boatbut()
{
imageselect.hiddenval.value = "boat"
imageselect.submit
}
</script>


????


thanks for your help

beetle
10-20-2002, 10:36 AM
Try this...<form name="imageselect" method="post" action="step_two.asp">

<input type="image" src="boat.jpg" width="100" height="142" onClick="return false; boatbut(this.form);">

<input type="hidden" id="hiddenval" name="hiddenval" value="">

</form>
<script language="JavaScript">

function boatbut(f)
{
f.hiddenval.value = "boat";
f.submit();
}
</script>

Bluemonkey
10-20-2002, 12:55 PM
thanks i will give it a go

RadarBob
10-20-2002, 05:12 PM
Beetle's right. You did not reference properly. B's solution has you passing in the form and that will work. Here's another solution, but I like Beetle's better. I think explicit parameter passing better documents and show's the programmer's intent better.


function boatbut() {
document.imageselect.hiddenval.value = "boat"
document.imageselect.submit
}
</script>

glenngv
10-21-2002, 07:43 AM
Originally posted by beetle
Try this...<form name="imageselect" method="post" action="step_two.asp">

<input type="image" src="boat.jpg" width="100" height="142" onClick="return false;boatbut(this.form);">

<input type="hidden" id="hiddenval" name="hiddenval" value="">

</form>
<script language="JavaScript">

function boatbut(f)
{
f.hiddenval.value = "boat";
f.submit();
}
</script>

will the submit image call the boatbut() function when there is a return statement before it?

input type=image already submits the form, so you can simply do it like this:

<input type="image" src="boat.jpg" width="100" height="142" onClick="this.form.hiddenval.value='boat'">

beetle
10-21-2002, 08:18 AM
glenngv

Yes, you are right...I must have been in a hurry. The return should be after...

You method should work just fine...or attach the same script line to the onSubmit event of the form...