...

View Full Version : Problem moving inline JS to a function??



RichardJW
10-19-2005, 12:50 PM
Hi, just a quick query. I have some inline javascript to submit a form with an onclick event.
I just recently decided to pull the script into a function and send the relevant URL info as a variable.
All seemed fine until I re-tested in IE5 - it now will not submit the form, although the code should be the same.
The function works in IE6, Opera, Safari, Camino and IE5.2 (Mac)
What has happened with it in IE5?!

Any thoughts?

Original inline JS:


onClick="window.document.myform.action='mypge2.asp';
window.document.myform.method='GET';
window.document.myform.submit(); return false;"


New function to replace inline JS (With alerts):


function nextpage(page) {
alert(page);
window.document.myform.action=page;
window.document.myform.method='GET';
alert(window.document.myform.method);
window.document.myform.submit();
return false;
}

Event to access function:


onClick="nextpage('mypge2.asp')"

nikkiH
10-19-2005, 02:05 PM
Why return false?
That might muck things up.

RichardJW
10-20-2005, 10:01 AM
Thanks for the reply nikkiH,
I just realised that the 'return false' was copied over from the onclick event and should not have been - thanks for pointing that out.
I have removed this from the function but unfortunately it doesn't seem to sort out the problem...strange, not really sure why this isn't working in IE5. A test page on the same machine with the original inline JS still works.

??

RJW

glenngv
10-20-2005, 12:00 PM
Where is the onclick attached?
Try this:


onClick="nextpage('mypge2.asp');return false;"

or put back the return false inside the function and do this:


onClick="return nextpage('mypge2.asp')"

If still this does not solve your problem, you need to elaborate on what was really happening. Does the page stop from submitting? At what point does the debug alert show?

RichardJW
10-20-2005, 03:09 PM
Glenngv,
Yes, it was the return false not being re-applied to the onclick link, putting it on the onclick for the function call sorted out the problem.
As posted:

onClick="nextpage('mypge2.asp');return false;"

Thanks for your help.

RJW



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum