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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submitting Form Problem 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
I'm having a mare trying to automate a login form.

1stly, if i use document.formname.submit(); I get "Object doesn't support this property or method", yet if i remove the submit button frm the form then the auto submit works fine.

Why does this happen?

Secondly the PHP script i'm submitting too must be checking that the submit button was presed , as if i auto submit the form, it doesn't work, but if i click the submit button it works.

How can i simulate pressing the submit button with JavaScript?

Thanks,
1DMF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
1DMF, you should know by now that we need to see your code to help with answers. [smile]


Nevertheless, I'll take some guesses.

1stly, if i use document.formname.submit(); I get "Object doesn't support this property or method", yet if i remove the submit button frm the form then the auto submit works fine.

By any chance do you have a button on your form named submit? I imagine you'd know not to do this, but I still have to ask. Additionally, to stay XHTML compliant, forms do not support the name attribute, only id. That said, you should use standards compliant code to accomplish the submission:

Code:
document.getElementById("formid").submit()

How can i simulate pressing the submit button with JavaScript?

There's pretty much only one way to do this, and I don't know how widely supported it is across all browsers. Some buttons have a click method that you can call to simulate pressing the button. I'm not sure if this extends out to submit buttons or just regular buttons, but here's an example that works in FF and IE7:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

window.onload = function () {
   document.getElementById("theButton").click();
};

</script>
<style type="text/css"></style>
</head>
<body>

<input type="button" value="click me" onclick="alert('test');" id="theButton" />

</body>
</html>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
you didn't need to see the code ;-)

apart from the fact it isn't mine, but you were right, I must be tired!

I shall try the click method though, this could be just what i'm looking for, many thanks, 1DMF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top