Connecting Tech Pros Worldwide Help | Site Map

Really Odd OnClick issue

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 4th, 2005, 08:45 PM
Laphan
Guest
 
Posts: n/a
Default Really Odd OnClick issue

Hi All

I'm using the same style of form on a number of pages, but for some reason
the exact same one liner on one my pages doesn't do anything. The one liner
is:

<INPUT TYPE="BUTTON" onClick="location.href='admin.asp?sec=4&folder=32' "
CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>

Basically the user clicks this button and it takes the back to the main
page, which is actually the same page, but the 'sec' determines what routine
the page is going to run and display.

The above works fine on my other pages, but not on one particular page so I
must have something in this page that is stopping it from working, but I
can't see what.

If I put an alert before the location.href bit, eg
onClick="alert('hello');location.href='admin.asp.. ., then the alert does
appear when I click the button, which means it's my location ref that is
fouling up.

What is even weirder is that if I stick window. in front of the
location.href command then it works, eg:

<INPUT TYPE="BUTTON"
onClick="window.location.href='admin.asp?sec=4&fol der=32'"
CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>

I know this solves my problem, but I'd like to know why this is the case.

Any help you can give would be appreciated.

Rgds Laphan




  #2  
Old December 4th, 2005, 09:35 PM
VK
Guest
 
Posts: n/a
Default Re: Really Odd OnClick issue


Laphan wrote:[color=blue]
> What is even weirder is that if I stick window. in front of the
> location.href command then it works, eg:
>
> <INPUT TYPE="BUTTON"
> onClick="window.location.href='admin.asp?sec=4&fol der=32'"
> CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>
>
> I know this solves my problem, but I'd like to know why this is the case.[/color]

Impossible to say w/o seeing the page itself. But the situation:
windows.location works - location doesn't gives a strong hint that on
this page you have:

a custom JavaScript object named "location"
or
an HTML element having id "location"

Also is it a single page or a frameset?

Did you also try:
onClick="window.location.href='admin.asp?sec=4&fol der=32'+(new
Date).getTime();"

  #3  
Old December 4th, 2005, 09:35 PM
Evertjan.
Guest
 
Posts: n/a
Default Re: Really Odd OnClick issue

Laphan wrote on 04 dec 2005 in comp.lang.javascript:
[color=blue]
> <INPUT TYPE="BUTTON"
> onClick="window.location.href='admin.asp?sec=4&fol der=32'"
> CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>
>
> I know this solves my problem, but I'd like to know why this is the case.
>[/color]

It probably is a matter of timing,
while the form-submit also executes.

Try:

<INPUT TYPE="BUTTON"
onClick="location.href='admin.asp?sec=4&folder=32' ;return false;"
CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>

or:

<BUTTON
onClick="location.href='admin.asp?sec=4&folder=32' ;"
CLASS="FormButton">Go back to list</BUTTON>




--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

  #4  
Old December 4th, 2005, 09:45 PM
RobG
Guest
 
Posts: n/a
Default Re: Really Odd OnClick issue

Laphan wrote:[color=blue]
> Hi All
>
> I'm using the same style of form on a number of pages, but for some reason
> the exact same one liner on one my pages doesn't do anything. The one liner
> is:
>
> <INPUT TYPE="BUTTON" onClick="location.href='admin.asp?sec=4&folder=32' "
> CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>
>
> Basically the user clicks this button and it takes the back to the main
> page, which is actually the same page, but the 'sec' determines what routine
> the page is going to run and display.
>
> The above works fine on my other pages, but not on one particular page so I
> must have something in this page that is stopping it from working, but I
> can't see what.
>
> If I put an alert before the location.href bit, eg
> onClick="alert('hello');location.href='admin.asp.. ., then the alert does
> appear when I click the button, which means it's my location ref that is
> fouling up.
>
> What is even weirder is that if I stick window. in front of the
> location.href command then it works, eg:
>
> <INPUT TYPE="BUTTON"
> onClick="window.location.href='admin.asp?sec=4&fol der=32'"
> CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>
>
> I know this solves my problem, but I'd like to know why this is the case.
>
> Any help you can give would be appreciated.[/color]

You may have a global variable named 'location', or you may have used
it for the name or id of an element somewhere. Try replacing the
onclick value with 'alert(location)' and see what happens, or search
for the string 'location' in the code.


--
Rob
  #5  
Old December 4th, 2005, 10:05 PM
Richard Cornford
Guest
 
Posts: n/a
Default Re: Really Odd OnClick issue

Laphan wrote:[color=blue]
> I'm using the same style of form on a number of pages, but
> for some reason the exact same one liner on one my pages
> doesn't do anything. The one liner is:
>
> <INPUT TYPE="BUTTON"
> onClick="location.href='admin.asp?sec=4&folder=32' "
> CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>[/color]
<snip>[color=blue]
> What is even weirder is that if I stick window. in front
> of the location.href command then it works, eg:[/color]
<snip>[color=blue]
> I know this solves my problem, but I'd like to know why this
> is the case.[/color]

It is going to be scope chain thing. There is something on the scope
chain of the event handler in that one page that is not present on the
other. Pure guess-work would suggest a form control with the name
'location'(so with the FORM element on the scope chain the Identifier
'location' refers to a named property of that FORM element, a reference
to the form control), but without being able to see the HTML it is not
possible to say for sure.

Richard.


  #6  
Old December 5th, 2005, 10:25 AM
Jasen Betts
Guest
 
Posts: n/a
Default Re: Really Odd OnClick issue

On 2005-12-04, Laphan <info@SpamMeNot.co.uk> wrote:

[not working]
[color=blue]
><INPUT TYPE="BUTTON" onClick="location.href='admin.asp?sec=4&folder=32' "
> CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>[/color]
[color=blue]
> What is even weirder is that if I stick window. in front of the
> location.href command then it works, eg:[/color]

possibly you have a field on that page called "location" ?

Bye.
Jasen
  #7  
Old December 5th, 2005, 02:45 PM
Jambalaya
Guest
 
Posts: n/a
Default Re: Really Odd OnClick issue

VK wrote:[color=blue]
> Did you also try:
> onClick="window.location.href='admin.asp?sec=4&fol der=32'+(new
> Date).getTime();"[/color]

Wow. Possibly the worst advice I've yet seen. Not only is this clearly
not a caching issue, but your date string is concatenated to the
"folder" value.

  #8  
Old December 5th, 2005, 03:25 PM
VK
Guest
 
Posts: n/a
Default Re: Really Odd OnClick issue

Thank you for pointing to my typo. Sh** happens :-)

onClick="window.location.href='admin.asp?sec=4&fol der=32&rnd='+(new
Date()).getTime();"

Unlikely but it may be a caching issue if URL
'admin.asp?sec=4&folder=32' has been already called during the session.

If it is not an issue yet then it eventually will be somewhere
sometimes if one uses GET method: it is enough to request the same asp
page more than once. So unrelated to the current problem link
randomization would be a good idea.

I would still bet on my first idea (global [location] var or object
interfering with window.location

  #9  
Old December 5th, 2005, 03:55 PM
Astra
Guest
 
Posts: n/a
Default Re: Really Odd OnClick issue

And the prize goes to Master Betts!!!

Thanks Jason (and everybody else for their help). I've just noticed that
I've named one of my fields as location when I want to name it as loc.

Doh!!! Doh !! Doh!!

Rgds


"Jasen Betts" <jasen@free.net.nospam.nz> wrote in message
news:398b.43940b35.39f3d@clunker.homenet...
On 2005-12-04, Laphan <info@SpamMeNot.co.uk> wrote:

[not working]
[color=blue]
><INPUT TYPE="BUTTON" onClick="location.href='admin.asp?sec=4&folder=32' "
> CLASS="FormButton" TABINDEX=41 VALUE='Go back to list'>[/color]
[color=blue]
> What is even weirder is that if I stick window. in front of the
> location.href command then it works, eg:[/color]

possibly you have a field on that page called "location" ?

Bye.
Jasen


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.