Page 1 of 1

reload same page with alternate output

Posted: Tue Nov 18, 2003 7:40 am
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() ?)

Posted: Tue Nov 18, 2003 8:30 am
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

Posted: Thu Nov 20, 2003 7:13 am
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