Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simulate a button on a form being pressed...

Status
Not open for further replies.

Ross1811

MIS
Oct 1, 2004
122
US
Is there anyway for javascript Function to simulate pressing a button such as submit on a form?


Thanks,
Ross
 
document.formName.buttonName.click()

or to submit the form directly

document.formName.submit()

Adam

recursion (n.) See recursion.
 
It does not seem to work, maybe I am missing something simple, I am calling the right form and button, just nothing is happening. Any ideas?
 

I'd use the second option given by Adam... you will have to ensure you do not have any form elements named "submit", however.

Failing that, you'll have to post your code.

Dan


The answers you get are only as good as the information you give!

 
this is my code,

<script>
function ShowPage()
{
document.form.submit()
}
</script>


<input type="reset" name="Submit2" value="Reset">
<inputname="Submit12"type="submit"id="Submit12"value="Query">
<input type="submit" name="Submit3"value="Insert">


Those are my buttons, all I need for it to do is go to and click the query button.


Ross


 
What's the name of the form? You have to refer to it by name, or by number:

document.forms[0].submit();

or

document.forms[formname].submit();

It's not a good idea to name a form "form", or use any other words like that ("text", "button", "checkbox", "submit") for element names or IDs.

But, as always, no real code, no real answers.

Lee
 
when u put a button type as submit, it will automatically submit the form...

if you need to run a special code when u do the submit u can do it in two ways:

1- specify a onsubmit action (note that in this case you have to add a return false in the showpage function, or else the form will be submitted twice

Code:
<form name="submitform" action="search.asp" onsubmit="javascript:showpage()">
... //remaining of form here
<input type="submit" value="query">
</form>

2- you just add a regular button and assign it to the function showpage

Code:
<form name="submitform" action="search.asp">
... //remaining of form here
<input type="button" value="query" onclick="javascript:showpage()">
</form>

Hope This helps

Cheers, Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top