Digital Point Forums
Quick Collect

Go Back   Digital Point Forums > Design & Development > Programming > JavaScript
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Mar 29th 2005, 6:01 am
fraser5002 fraser5002 is offline
Peon
 
Join Date: Mar 2005
Posts: 10
fraser5002 is on a distinguished road
radio buttons if then else

hi after having been giving great help the othe rday i have one more problem i would like to ask about. im trying to use a function to work out which radio button has been selected. I dont really fully understand functions so i hope i have set this out right . Anyway its not working and errors appear on the page.

am i close?

Code:
<form name="payment">
<div align="center">
  <table border="0" height="74" width="371">
    <tr>
      <td height="12" width="600">
        <p align="right"><font size="2">I'm buying a £0.50 photo&nbsp;
        (1600 x 1200)</font></p>
      </td>
  <center>
      <td height="12" width="26"><input type="radio" value="V1" checked name="R1"></td>
      <td height="12" width="29">&nbsp;&nbsp;</td>
    </tr>
  </center>
    <tr>
      <td height="25" width="600">
        <p align="right"><font size="2">I'm buying a £1.00 photo (2048
        x 1536)</font></p>
      </td>
  <center>
      <td height="25" width="26"><input type="radio" name="R1" value="V2"></td>
      <td height="25" width="29"><font size="2">
      
      <img border="0" src="x-click-but23.gif" align="center" width="68" height="23" onclick="decision(<V1>,<V2>,<V3>)">

      </font></td>
    </tr>
  </center>
    <tr>
      <td height="25" width="600">
        <p align="right"><font size="2">I'm buying a Image CD costing
        £6.00</font></p>
      </td>
  <center>
      <td height="25" width="26"><input type="radio" name="R1" value="V3"></td>
      <td height="25" width="29"></td>
    </tr>
  </table>
  </center>
</div>

<p align="center"><font size="2">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font>
</p>
<script type="text/javascript">
      <!--
function decision(V1,V2,V3){
  if(document.form.V1.checked) {
    window.alert("test");
  } else if(document.form.V2.checked) {
    window.alert("test");
  } else if(document.form.V3.checked) {
    window.alert("test");
  } else {
    window.alert("Pick something!!");
  }
}// -->
</script>


</form>
thanks again

Last edited by fraser5002; Mar 29th 2005 at 6:09 am.
Reply With Quote
  #2  
Old Mar 29th 2005, 7:13 am
draculus draculus is offline
Grunt
 
Join Date: Oct 2004
Location: Cork, Ireland
Posts: 63
draculus is on a distinguished road
When radio buttons have the same name to group them together javascript treats them as an array not individual elements. So your function needs to change to:

function decision(V1,V2,V3){
if(document.form.R1[0].checked) {
window.alert("test");
} else if(document.form.R1[1].checked) {
window.alert("test");
} else if(document.form.R1[2].checked) {
window.alert("test");
} else {
window.alert("Pick something!!");
}
}


The parameters you are passing to the function are not used.
Reply With Quote
  #3  
Old Mar 29th 2005, 7:35 am
fraser5002 fraser5002 is offline
Peon
 
Join Date: Mar 2005
Posts: 10
fraser5002 is on a distinguished road
thansk for your advice i have changed the code to what you said but i am still getting errors. This is the page
http://homepage.ntlworld.com/fraser_d/buy-scottish-photos.htm
i just cannot work it out any ideas of what else im doing wrong?
thanks
Reply With Quote
  #4  
Old Mar 29th 2005, 8:43 am
draculus draculus is offline
Grunt
 
Join Date: Oct 2004
Location: Cork, Ireland
Posts: 63
draculus is on a distinguished road
This line is incorrect:

<img border="0" src="x-click-but23.gif" align="center" width="68" height="23" onclick="decision(<V1>,<V2>,<V3>">

The closing bracket on the decision function call is missing. I also do not see what the <V1> etc parameters are. Change the above line to:

<img border="0" src="x-click-but23.gif" align="center" width="68" height="23" onclick="decision()">

and change thew function header to:

function decision() {

That will remove your javascript errors.
Reply With Quote
  #5  
Old Mar 29th 2005, 10:06 am
fraser5002 fraser5002 is offline
Peon
 
Join Date: Mar 2005
Posts: 10
fraser5002 is on a distinguished road
thansk for your advice spot on! nearly there just a couple more bugs
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Voting Buttons H-Man Google 3 Sep 25th 2006 9:25 pm
Need person to make some buttons bluemouse2 Link Exchange 10 Mar 23rd 2005 9:15 am
Google Toolbar voting buttons dfsweb Google 10 Jan 18th 2005 12:46 pm


All times are GMT -8. The time now is 8:00 pm.