Tabatha M
Tabatha M

Reputation: 171

html form submit button

I have a form and when the form is loaded through a browser, I want it to submit the data automatically.

The problem is I wrote a PHP script that will submit it all fine on a test form. My problem is the server I'm trying to submit the data to named the button "submit".

Here is the example form:

<html>

<head>
</head>

<form  action="http://www.example.com/post.php"  method="post">
    <input type="text" name="input1" value="test1"  />
    <input type="text" name="input2" value="test2"  />
</form>

<script type="text/javascript">
    document.forms[0].action="submit"
</script>

</body>

</html>

The person that created the form on the other server named it "submit". Is there a workaround until they fix it?

Here is a example of the person's form

<html>

<head>
</head>

<form  action="http://www.example.com/post.php"  method="post">
    <input type="text" name="input1" value="test1"  />
    <input type="text" name="input2" value="test2"  />
    <input type="submit" name="submit" class="submit" value="Send Data" />
</form>

</body>

</html>

Upvotes: 0

Views: 8600

Answers (3)

iamgopal
iamgopal

Reputation: 9132

If I understand your question correctly, the input element has name="submit" and type="submit". They are different things.

So you can also create the same behavior easily.

Upvotes: 0

StjepanV
StjepanV

Reputation: 167

Instead of:

<html>
<head>
</head>
<form  action="http://www.example.com/post.php"  method="post">
<input type="text" name="input1" value="test1"  />
<input type="text" name="input2" value="test2"  />
</form>
<script type="text/javascript">
document.forms[0].action="submit"
</script>
</body>
</html>

Try this:

<html>
<head>
</head>
<form name="MyForm" action="http://www.example.com/post.php"  method="post">
<input type="text" name="input1" value="test1"  />
<input type="text" name="input2" value="test2"  />
</form>
<script type="text/javascript">
document.MyForm.submit();
</script>
</body>
</html>

Upvotes: 0

ThiefMaster
ThiefMaster

Reputation: 318708

You want to submit the form? Then simply use its submit() method:

document.forms[0].submit();

If the server expects submit to be POSTed, i.e. the button being clicked, you can simply trigger the click() event of the button. Since you cannot access it using its name, I'd use jQuery for it:

$('input[name="submit"]').click();

Upvotes: 1

Related Questions