Problem submitting a form using onclick
I'm having a problem submitting my form, my code is as follows:
<form method="get" action="<?=bloginfo('template_url');?>/contact.php" id="quickContactForm" onsubmit="return sendDetails();">
<h2>Request a callback:</h2>
<ul style="margin:10px">
<li style="list-style-type:none;">
<label>Name:</label>
<input name="name" id="name" type="text" style="margin-left:12px; height:20px; margin-bottom:5px;">
</li>
开发者_StackOverflow中文版 <li style="list-style-type:none;">
<label>Email:</label>
<input name="email" id="email" type="text" style="margin-left:14px; height:20px; margin-bottom:5px;">
</li>
<li style="list-style-type:none;">
<label>Mobile:</label>
<input name="mobile" id="mobile" type="text" style="margin-left:8px; height:20px; margin-bottom:5px;">
</li>
<li style="list-style-type:none;">
<label>Note:</label>
<input name="interest" id="interest" type="textarea" style="margin-left:20px; height:100px">
</li>
<li style="list-style-type:none;">
<a href="javascript: void(0)" onclick="document['quickContactForm'].submit()" class="">
<img src="<?=bloginfo('template_url');?>/images/btn_send.jpg" />
</a>
</li>
</ul>
</form>
The above code gives me an error: document.quickContactForm is undefined I've also tried changing the tag to:
<a href="javascript: void(0)" onclick="$('#quickContactForm').submit()" class="">
<img src="<?=bloginfo('template_url');?>/images/btn_send.jpg" />
</a>
but this gives me an error aswell: $ is not defined
What am I doing wrong ?
Regards, Stephen
$
is used by libraries such as jQuery, but it is not part of JavaScript. Are you including a tag targeting a jQuery file?
Try using document.getElementById("quickContactForm").submit();
You can't get an ID unless you reference it on the forms object: document.forms.quickContactForm
. (Or if you use document.getElementById('quickContactForm')
)
精彩评论