• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

javascript submit form with submit or button... automatically

I have a form that can be sumbitted with a sumbit or button type.

I was using  a submit type.

The form was submitted automatically with:
<form name=myform action=action.html method=post>
</form>
<script>
document.myForm.submit();
</script>

Now I changed the sumbit button and put an image. With an onclick="sumbit();" When I click it goes well
but I need an equivalent of the script that automatically send the form

0
robrodp
Asked:
robrodp
  • 4
  • 3
1 Solution
 
Tomarse111Commented:
I'm not sure if I understand the problem correctly; you need the page to submit when a user clicks your image? on when they press the return the key?

A bit more detail would be helpful :-)
0
 
hieloCommented:
>>With an onclick="sumbit();"
Well, if you did a copy and paste, the problem is you misspelled submit()

other than that, make sure NO element on the html page has name="submit" nor id="submit"
0
 
robrodpAuthor Commented:
I want the form to be submitted as soon as it is loaded. No clicking anywhere
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
hieloCommented:

<form name="myform" id="myform" action="action.html" method="post">
...
</form>
<script>
window.onload=function(){
  document.myform.submit();
}
</script>

Open in new window

0
 
robrodpAuthor Commented:
I know it works. The problem is the original form has an image with an onclick that submits the form. When it is received by tha action it recognizes it comes from an image with a name and an id etc. and does waht it is supposed to do.

If submitted (not from an image) it does not do what it is supposed to do
0
 
hieloCommented:
post your form
0
 
robrodpAuthor Commented:
If I run the code as below it works...  action does it job

if I delete the onclick from the image and replace it with a submit or make it autosubmit (with a function like proposed above) id does not do what it is supposed to do.

As if the receiveing page (action) recognizes it was invoked by and image click and (perhaps its parameters)


<form name="MyForm" method="post" action="http://whateveraction.com/" id="MainForm"">
<input name="HomeSearch1$txtQue" type="text" maxlength="50" id="HomeSearch1_txtQue" tabindex="1" class="campo_busqueda" value="love"  />
<input name="HomeSearch1$txtDonde" type="text" maxlength="50" id="HomeSearch1_txtDonde" tabindex="2" class="campo_busqueda" value="texas" onkeypress="return clickButton(event,'HomeSearch1_btnBuscarimg')" />
<input type="image" name="HomeSearch1$btnBuscarimg" id="HomeSearch1_btnBuscarimg" src="uiResources/bot_buscar.gif"  border="0" /><span id="HomeSearch1_lblError" onclick="submit();")></span>&nbsp;

Open in new window

0
 
hieloCommented:
what about:
window.onload=function(){
clickButton(window.event,'HomeSearch1_btnBuscarimg');
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now