Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-19-2005, 12:50 PM   PM User | #1
RichardJW
New Coder

 
Join Date: Sep 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
RichardJW is an unknown quantity at this point
Problem moving inline JS to a function??

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:

PHP Code:
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):

PHP Code:
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:

PHP Code:
onClick="nextpage('mypge2.asp')" 
RichardJW is offline   Reply With Quote
Old 10-19-2005, 02:05 PM   PM User | #2
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
Why return false?
That might muck things up.
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 10-20-2005, 10:01 AM   PM User | #3
RichardJW
New Coder

 
Join Date: Sep 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
RichardJW is an unknown quantity at this point
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
RichardJW is offline   Reply With Quote
Old 10-20-2005, 12:00 PM   PM User | #4
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Where is the onclick attached?
Try this:

Code:
onClick="nextpage('mypge2.asp');return false;"
or put back the return false inside the function and do this:

Code:
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?
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app

Last edited by glenngv; 10-20-2005 at 12:03 PM..
glenngv is offline   Reply With Quote
Old 10-20-2005, 03:09 PM   PM User | #5
RichardJW
New Coder

 
Join Date: Sep 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
RichardJW is an unknown quantity at this point
Thumbs up That's it working now.

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:
Code:
onClick="nextpage('mypge2.asp');return false;"
Thanks for your help.

RJW
RichardJW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:19 AM.


Advertisement
Log in to turn off these ads.