Forum Moderators: open

Message Too Old, No Replies

Dynamic writing of an onSubmit event

         

potato95

3:46 pm on Feb 7, 2006 (gmt 0)

10+ Year Member



I have an html form that has a POST action but no onSubmit event handler.
ie
<form name=testForm action="https://www.example.com/purchase" method=POST>
<input type=hidden value="1238" name="cartId">
<INPUT TYPE=submit VALUE="SECURE PAYMENT">
</form>

For various reasons I do not have access to add an onsubmit event handler directly.

Can this be written on the client with javascript? I have tried this but can't seem to get the onSubmit event to work. The below function is triggered by <body onload=writeOnSubmit();>

function writeOnSubmit(){

if(document.getElementsByTagName("form").item(4))
{
document.getElementsByTagName("form").item(4).onSubmit="javascript: myHandler()";
}

}

Can this be done?

Many thanks.

Bernard Marx

3:51 pm on Feb 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



(--).onSubmit=myHandler;

potato95

4:23 pm on Feb 7, 2006 (gmt 0)

10+ Year Member



Many thanks, you have saved me a lot of time.

Bernard Marx

4:42 pm on Feb 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm. Funny. That shouldn't work. Should be:

onsubmit=myHandler;