1

Hi I have the following script in my form

function pdf() {
var frm = document.getElementById("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 ?

Daniel Vassallo
346k72 gold badges514 silver badges447 bronze badges
asked Mar 28, 2010 at 12:59
2
  • 1
    programming related questions are belong to stackoverflow.com btw, I think u need to add ID=form1 to your input class. Commented Mar 28, 2010 at 13:00
  • 1
    Can we see some HTML please? Specifically, the form? Commented Mar 28, 2010 at 13:09

3 Answers 3

2

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" />
answered Mar 28, 2010 at 13:09
Sign up to request clarification or add additional context in comments.

3 Comments

No. While it is good style to explicitly end statements with semi-colons because certain cases don't otherwise end the statement where you might expect, that isn't the problem here.
@David, I suggested this as a good practice, I agree with you that probably is not the issue here, but you never know, what if the script is compressed with a packer?
A decent packer will fix that. If it isn't a good packer then I would expect it to error before successfully setting the target property.
1

Make a form like this:

<form id="form1" action="" onsubmit="pdf();return false;">
 <input class="buttn" type="submit" value="Test" value="Test" />
</form>
answered Mar 28, 2010 at 13:19

3 Comments

this is a better approach but Darin Dimitrov is right about the syntax error. Also he should just return true in pdf() instead of submiting and returning false shouldn't he?
Is he submiting the same form?
Its very difficult to tell what is actually being suggested here, but it looks like it boils down to "Use onsubmit instead of onclick" — that won't solve the problem, and likely wouldn't fit the situation which looks like wanting to submit to a different address if a particular button is clicked.
0

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?

answered Mar 28, 2010 at 13:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.