PDA

View Full Version : onClick -- reload page possible?


Nomadicus
12-03-2002, 04:14 PM
Is it possible to have JS reload the page via an onClick event?

Depending on what the user chooses in one list box, I have some other list boxes I want to repopulate (via other scripts) and simply want to force a reload of the page so the scripts will run.

I don't know what this reload event looks like in JS.

Thanks in advance.

Vladdy
12-03-2002, 04:25 PM
Why on earth do you need to reload the page to make scripts run. :confused: :confused: Especially those that populate form elements...
What happened to puting the script you need to execute in a function and running it onclick?

Nomadicus
12-03-2002, 06:11 PM
I write most of my scripts in PHP, with an occasional Jscript as needed for client side stuff. But Jscript is notoriously buggy across platforms and browsers. PHP is pretty solid.

Also, unlike JS, PHP is pretty straightforward to program in. Anybody that know C or C++ can pick it up in a couple of weeks, or less. And I don't know JS all that well.

I have two list boxes on a form. One is a list for languages, German, French, English, etc. The other is a list of months. When the user changes languages, the months list also change. This works fine in some browsers, but not others. Netscape 4.7 esp. does not like this stuff, while NS 7.0 and IE 5.5 like it just fine.

My plan is to re-implement those list boxes in PHP. I already have code to do that. I also send the user a cookie when he selects his language choice for his default. So by reloading the page with onClick (in the language list box, and yes, I can intermingle JS with PHP, but not the other way around) I will grab the cookie and refresh the list boxes as needed.

I would like to do this all in JS. But as stated, it's just to unreliable and is causing to many problems across browsers.

Can you tell me if it's possible to have the onClick event call something to reload the page.

Thanks.

Vladdy
12-03-2002, 06:33 PM
Seems like too much trouble to keep minority happy :rolleyes:
window.location.href = 'filename.html' should reload the page

Membie
12-03-2002, 08:00 PM
onClick (or any other event handler)="window.location.reload()"

Nomadicus
12-03-2002, 08:14 PM
Thanks, that's just what I was looking for.

Now when the user selects a different language in the list box, the onClick event calls a JS function that :

1. sends a new language cookie

2. reloads the page

The PHP scripts then run, and the list boxes get rebuilt with the correct data (by checking the language cookie). Works great, if you don't mind the temporary server delay in reloading the page. But it's a much simpler design than what I had when trying to do this all in JS.

PHP and JS can be a terrific combo, if you know how to mix them.