Javascript Submit
Hi I have the following script in my form
function pdf() {
var frm = document.getEl开发者_C百科ementById("form1");
frm.action = "http://www.abbysoft.co.uk/index.php";
frm.target="_blank"
frm.submit()
}
this is called from the following in my form
<input class="buttn" type="button" value="Test" onclick="pdf()"
The code work up to the frm.submit() but it will not submit
Can anyone offer any advice please ?
You should end your statements with ;
. The following should work
function pdf()
{
var frm = document.getElementById('form1');
frm.action = 'http://www.abbysoft.co.uk/index.php';
frm.target = '_blank';
frm.submit();
}
assuming you have a form like this:
<form id="form1" action="#">
<input class="buttn" type="button" value="Test" onclick="pdf()" value="Test" />
</form>
Also make sure that by any chance you don't have an input with name submit
inside your form as this would override the submit
function:
<input type="text" name="submit" />
Make a form like this:
<form id="form1" action="" onsubmit="pdf();return false;">
<input class="buttn" type="submit" value="Test" value="Test" />
</form>
You haven't given us the code you are using to create the form, nor have you told us what (if any) errors are reported by the browser, however, the usual cause for this issue is having a submit button named or ided submit.
Any form control is accessible from the form object with a property that matches its name (and another one that matches its id if that is different). This clobbers any existing properties of the form (other than other controls) including the submit
and reset
methods.
The simplest solution is to rename the control so it doesn't conflict with an existing property.
Alternatively, see How to reliably submit an HTML form with JavaScript?
精彩评论