PDA

View Full Version : problems submitting form


skdzines
01-29-2005, 01:47 PM
I am using php to validate and submit a form. I am trying to use a rollover image to submit the form. I have the following code that works perfectly on another site I have done which I copied to the site I am currently working on. The code is as follows:

<form name="contact" method="post" action="<? $PHP_SELF ?>">
//form elements here....


<a href="#" onClick="document.contact.submit();" onMouseOver="document.contact.SubmitIMG.src='contact/images/submitFormOn.gif';" onMouseOut="document.contact.SubmitIMG.src='contact/images/submitFormOff.gif';">
<img src="contact/images/submitFormOff.gif" name="SubmitIMG" width="74" height="18" border="0" id="SubmitIMG"></a>
</div></td><input type="hidden" name="form" value="contact">
</tr>
</table>
</form>


For some reason I get this error when I rollover or click the submit button image.

Line: 210
Char: 1
Error: 'document.contact.SubmitIMG' is null or not an object.

I don't understand why I am receiving this error. Like I said I basically copied the code from another site I did and just changed the path to the image I need to use. The form names and everything else are the same.

Any ideas? Please help!!!

Thanks

jbbrwcky
01-29-2005, 02:18 PM
For every instance of document.contact change it to document.getElementById('contact').

Jbbrwcky

skdzines
01-29-2005, 02:37 PM
Thanks jbbrwcky

I haven't tried your solution yet because I got it working. I realized I had another rollover image name="contact" which was causing the problem. Because the form name was called contact I just changed the name of the rollover to contactButton and everything works now.

Thanks for your help.

tommeh
02-01-2005, 02:57 PM
<a href="#" onClick="document.contact.submit();" ...


first, to submit the form, the syntax must be

document.forms.contact.submit();

you need to add the 'forms' after the document object.

also, instead of putting href="#" and using an onClick attribute, you can just put

href="javascript:document.forms.contact.submit();" (no space between 'java' and 'script')