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!

Werid Form submit issue

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
I do this all the time. I have a submit button and a print button.

when I click the submit button I submit my page to the same page and when I click the print button i submit my form to a different page.

For some reason I get this message."document.myform.submit is not a function"

When I get rid of my input type "submit" Everything works like it should..

Anyone know whats going on.

Here is my code.

Code:
<script>
function submitform()
{
 

  document.myform.action = 'reportprint.cfm';
  document.myform.submit();
}
</script>

<form name="myform" action="reports.cfm" method="post" >

</tr>
	<tr><td colspan="8" align="center"><!--- <input type="submit" name="submit" value="submit"> ---></td>
	<tr>
		<td colspan="8" align="right"><input type="button" name="Print" value="Print" onclick="submitform();"></td>
	</tr>
	  </form>

When I add the input type submit the print stops working. Now it works fine
 
I played with this code, strangely enough, it's cause you have name="submit" on your submit botton.

It's defaulting to document.myform.submit()

where it's trying to get the element submit from your form and not actually trying to submit it.

So change your submit button name, and you should be ok.

[monkey][snake] <.
 
Thanks I will try this. Shouldnt it just submit my form instead of looking for submit name?
 
Apparently the first thing it does is see if a name exists by the string given after the form name THEN looks to see if a form method is passed.

I was unaware of this behavior until yesterday, cause I seldom give names to HTML elements, I ususally use ids, either way is fine though.

[monkey][snake] <.
 
this is the reason it is important that you use the proper/preferred methods of referencing forms and elements.

Here are a couple of variations on your function that should work fine:

Code:
function submitform() {
  document.forms['myform'].action = 'reportprint.cfm';
  document.forms['myform'].submit();
}

Code:
function submitform() {
  // you will need to give your form an id of "myform" for this to work
  document.getElementById('myform').action = 'reportprint.cfm';
  document.getElementById('myform').submit();
}

consequently, you should never use javascript keywords as names of elements. "submit", "if", "action", "reset", etc. should always be avoided.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top