[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 512
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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