homepage Welcome to WebmasterWorld Guest from 54.163.70.249
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
onclick="" Browser Compatibilty
onclick="javascript:window.location.href('cart.asp');"
davemarks




msg:1484143
 6:38 pm on Apr 2, 2003 (gmt 0)

I've been using

<input type="button" class="button" value="View Shopping Basket" onclick="javascript:window.location.href('cart.asp');">

as part of a button, without a form. It makes for handy navigation on various pages.

The problem, is I have recently discovered this seems to throw up an error in IE5 and possibly NS6 aswell.

Not sure about IE5.5 can anybody say either way?

My main question is, do you know why it doesn't work. Is it becuase of the way I'm doing it. I've had problems with window.location compatibility before...

If not can you suggest a better way of doing it? I would prefer to keep the button if at all possible

Thanks in advance :)

Dave

 

wruk999




msg:1484144
 7:27 pm on Apr 2, 2003 (gmt 0)

Hi Dave,

using IE5, I get no errors with the following code:


<input class="default" type="BUTTON" name="BtnCancel" value="Back" onClick="JavaScript:document.location='default.php'">

Does that make any diference for you?

Regards,
William.

DrDoc




msg:1484145
 7:35 pm on Apr 2, 2003 (gmt 0)

Well, technically location is a window element. However, the parenthesis shouldn't be there...

Change your code to this:

javascript:window.location.href='cart.asp';">

gsx




msg:1484146
 9:26 pm on Apr 2, 2003 (gmt 0)

surely it's better to:

<form action="cart.asp">
<input type="submit" value="View Basket">
</form>

You are not relying on the user having JavaScript enabled, and the above code (or pseudocode - I haven't checked it) should work on almost any browser (except maybe Netscape 0.5!).

davemarks




msg:1484147
 7:07 am on Apr 3, 2003 (gmt 0)

Cheers all, it was the () that was causing the problems.

The main reason I didn't use a form, was because theres another form on the page, with the submit button to the right of this one. Also having two forms one after the other causes problems being on the same line. I guess if i stuck them in a table it might work....

Hmmm will have to play a little more. Thanks for your help though!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved