reload same page with alternate output

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
vasilis
Forum Commoner
Posts: 40
Joined: Tue Apr 22, 2003 7:37 am

reload same page with alternate output

Post by vasilis »

I have a form which is produced by a php script and consists of 2 radio button inputs (radio1 and radio2) and one select input. I want to add code (javascript I guess) that when the user clicks on the 2nd radio input, the form reloads but with the select menu missing. The closest method i have thought of is to add a hidden input named "radio2_clicked" in the form and add an onClick event handler to the radio2 input, i.e.

Code: Select all

<input type=radio name=radio2 value=somevalue onClick="window.location.href=location.href;myform.radio2_clicked.value=1">
so when the form page reloads, the php script checks the value of the $radio2_clicked variable and if it finds it equal to 1 it doesnt output the select input element.

The problem with the above method is that the href property of the location object is undefined, probably because the form page is produced from a script. Is there any other javascript method I could use which reloads the same page but with the updated value of the $radio2_clicked variable? (e.g. the location.reload() ?)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

You can post your form from js:

Code: Select all

&lt;input ......... onclick="myform.radio2_clicked.value=1; myform.submit()"&gt;
&lt;input type=submit value="OK" name="submit"&gt;

Code: Select all

//..........skipped
if($_POST["submit"]=="OK"){
    //....... actual submit, user clicked OK
}elseif($_POST["radio2_click"]=="1"){
   //.... just reload form without selectbox
}else{
   // display form with selectbox
}
//..........skipped
vasilis
Forum Commoner
Posts: 40
Joined: Tue Apr 22, 2003 7:37 am

Post by vasilis »

thanks for your help. I have done the same myself too. I used the submit() method for the form and on the script that runs I wrote code that takes into account the $radio2_clicked variable. I am trying to catch up with Javascript a little bit
Post Reply