Jump to content

onClick radion button help


ded

Recommended Posts

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

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.