Jump to content

JavaScript form submition


grasperstail

Recommended Posts

Can't figure out how to submit this form. I tried all kinds of ways to reference the form and submit button elements but they won't submit the form when I call the method. What gives?

function page_setter(place_holder,keyword){			var frm = document.getElementById("client_frm");	var kywrd_search = document.getElementById("kywrd");	var page_set = document.getElementById("frm_page_set");	var browser = navigator.appName;	var brow_version = navigator.appVersion;	var version_number = parseFloat(brow_version);		page_set.value = place_holder;	kywrd_search.value = keyword;					if (browser == "Microsoft Internet Explorer"){		if (version_number == "4"){		document.getElementById("submit").click();	} 	}else{	frm.submit();	}	}"<td><a href='java script:void();' id='page_next' 		onclick='page_setter(\"$next\",\"$implode_trimmed\");'>>NEXT</a></td>";

Link to comment
Share on other sites

To submit a form just do this:HTML:<form ... ... id="something">...</form>java script:document.getElementById("something").submit();
Something could be wrong with my code but I've tried doing that. It seems like the code fails at the submit part. I don't know where else to look. It works fine in Firefox and when I updated to IE7 it works. I know most of my users are going to have older version of IE and I need it to work for them.
Link to comment
Share on other sites

Of course it doesn't work in IE 6. Have a look at this bit of code

		if (browser == "Microsoft Internet Explorer"){		if (version_number == "4"){		document.getElementById("submit").click();	} 	}else{	frm.submit();

Now, first it checks whether your browser is IE. If yes, then it checks whether it is version 4. If yes, it simulates a click on the submit button. If it is IE but not version 4, then it does nothing. For not IE and not version 4 it uses the submit method. I think what you want is

		if (browser == "Microsoft Internet Explorer" && version_number == "4") {		document.getElementById("submit").click();	} else frm.submit();

Btw hardly anyone uses IE 4 nowadays so I think it would be safe to remove that condition.

Link to comment
Share on other sites

  • 2 weeks later...
Of course it doesn't work in IE 6. Have a look at this bit of code
		if (browser == "Microsoft Internet Explorer"){		if (version_number == "4"){		document.getElementById("submit").click();	} 	}else{	frm.submit();

Now, first it checks whether your browser is IE. If yes, then it checks whether it is version 4. If yes, it simulates a click on the submit button. If it is IE but not version 4, then it does nothing. For not IE and not version 4 it uses the submit method. I think what you want is

		if (browser == "Microsoft Internet Explorer" && version_number == "4") {		document.getElementById("submit").click();	} else frm.submit();

Btw hardly anyone uses IE 4 nowadays so I think it would be safe to remove that condition.

Well in the end I did not need to specify browser version to solve the submission problem. The issue was caused by the "java script:void(0)" value for the href attribute in a link calling the submit function. I found that this value stops the page moving to another by its very nature. Therefore my page would never submit no matter what. Although IE7 and Mozilla handle the java script:void(0) value differently causing confusion. I corrected my problem by giving the '#' value for the href attribute. As far as the comment about whether or not to check for version 4 browsers and whether or not anyone is using this version, the truth is that when you call the browser.version method in javascript, it returns version 4 (only for IE browsers) in spite of your browser version actually being 5 or 6 (not sure what it does for 7). There are many folks still using version 6. At least in my office and these are the folks who are my clients. Thanks Microsoft!! :) for more info on this check out: http://blog.reindel.com/2006/08/11/a-hrefj...avoid-the-void/cheers!!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...