ded Posted May 4, 2009 Share Posted May 4, 2009 I am not sure if I am even in the correct direction. I want the $rm1pckcst to update automatically on the website once a radio button is selected. Here is my current code: <HTML> <HEAD> <TITLE>Radio Button onClick Handler</TITLE> <SCRIPT LANGUAGE="JavaScript"> var rm1packagecost = 0; function setRm1PkgCst(rm1desc) { $rm1packagecost = rm1desc } </SCRIPT> </HEAD> <body> <center><strong><font color="#337ABE" size="+2">Single Occupany Hotel Booking</font></strong></center> <br /> <form action="postsingle.php" method="post" enctype="multipart/form-data"> <table align=center width=80%> <tr><td align="center"><strong>Price per Player/Official = $700</strong></td> <td align="center"><strong>Price per Supporter = $725</strong></td> <td align="center"><strong>Extra Night Cost = $65/night</strong></td> </tr></table> <table align="center" width=80% border="2" style="font-size:12px"> <tr> <th>Room</th> <th>Names</th> <th>Player/Official<br> or Supporter</th> <th>Package Cost </th> <th># of Extra Nights </th> <th>Total Cost </th> </tr> <tr> <td align="center">1</td> <td align="center"><input name="rm1name" type="text" size="20" /></td> <td><input name="rm1desc" type="radio" value="Player/Official" onClick="setRm1PkgCst(rm1desc)"> Player/official <br> <input name="rm1desc" type="radio" value="Supporter" onClick="setRm1PkgCst(rm1desc)">Supporter</td> <td align="center"><?php $rm1packagecost ?></td> <td align="center"><input name="rm1name" type="text" size="2" /></td> <td align="center"><?php $rm1cost ?></td> </tr> </table> <br /> <center> <input name="Submit" value="Submit Form" type="submit"> </center> </form> </body> </HTML> Regards, DED Quote Link to comment https://forums.phpfreaks.com/topic/156728-onclick-radion-button-help/ Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 You can't do that. PHP lives on the server so assigning a PHP var to a JS one is impossible without the help of AJAX or something similar. Quote Link to comment https://forums.phpfreaks.com/topic/156728-onclick-radion-button-help/#findComment-825294 Share on other sites More sharing options...
ded Posted May 4, 2009 Author Share Posted May 4, 2009 OK....thanks. Quote Link to comment https://forums.phpfreaks.com/topic/156728-onclick-radion-button-help/#findComment-825309 Share on other sites More sharing options...
the182guy Posted May 4, 2009 Share Posted May 4, 2009 There are a lot of scenarios where you would want to pass PHP variables to JS. It certainly is very possible. I have demonstrated how it can be done without the use of AJAX in this thread here: http://www.phpfreaks.com/forums/index.php/topic,250672.0.html Quote Link to comment https://forums.phpfreaks.com/topic/156728-onclick-radion-button-help/#findComment-825580 Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 There are a lot of scenarios where you would want to pass PHP variables to JS. It certainly is very possible. I have demonstrated how it can be done without the use of AJAX in this thread here: http://www.phpfreaks.com/forums/index.php/topic,250672.0.html Have you even looked at his code...? He's trying to assign a PHP variable to a Javascript variable: function setRm1PkgCst(rm1desc) { $rm1packagecost = rm1desc } Quote Link to comment https://forums.phpfreaks.com/topic/156728-onclick-radion-button-help/#findComment-825622 Share on other sites More sharing options...
the182guy Posted May 4, 2009 Share Posted May 4, 2009 Maq, yes I have looked at his code. I believe he is trying to use radio buttons to select a package, and when clicked the price is updated on the page. There is a very simple solution to this which is what I have linked to. Quote Link to comment https://forums.phpfreaks.com/topic/156728-onclick-radion-button-help/#findComment-825627 Share on other sites More sharing options...
Maq Posted May 4, 2009 Share Posted May 4, 2009 Maq, yes I have looked at his code. I believe he is trying to use radio buttons to select a package, and when clicked the price is updated on the page. There is a very simple solution to this which is what I have linked to. I understand what you do in the technique you linked to, which is fine if you're assigning a client-side variable to a server-side one (JS = PHP), but he's trying to assign a server-side to a client-side (PHP = JS), which is impossible without a response back to the server (AJAX). Quote Link to comment https://forums.phpfreaks.com/topic/156728-onclick-radion-button-help/#findComment-825630 Share on other sites More sharing options...
the182guy Posted May 4, 2009 Share Posted May 4, 2009 Maq, you are right he should not be using that syntax inside a <script> tag. We'll have to wait for ded to explain further to find out what he actually wants to achieve, but it looks like he wants to select different packages and have the price change depending on the package - could be wrong though. Quote Link to comment https://forums.phpfreaks.com/topic/156728-onclick-radion-button-help/#findComment-825655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.