472,328 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Javascript and asp radio button array

Hi, can anyone help here?
I have the following code generated from a database, I want to have javascript calculate the

costs of the selected items using radio buttons, subtotal the costs and grandtotal the costs

ready for the selected items to be inserted back to the database. I did something like this

before with Checkboxes, but Radio button have to be named the same to maintain their

groupings.

Radio Button index is generated from the recordset using asp
Expand|Select|Wrap|Line Numbers
  1. <td>
  2. <%=(EquiptRS.Fields.Item("EquiptDescr").Value)%>
  3.         <input name="descr1" type="hidden" id="descr1" 
  4.  
  5. value="<%=(EquiptRS.Fields.Item("EquiptDescr").Value)%>" />
  6.         <input name="quantity<%=(EquiptRS.Fields.Item("EquipmentID").Value)-1%>" 
  7.  
  8. type="hidden" id="quantity<%=(EquiptRS.Fields.Item("EquipmentID").Value)-1%>" value="1.00" 
  9.  
  10. /></td>
  11.     <td><input name="price<%=(EquiptRS.Fields.Item("EquipmentID").Value)-1%>" type="radio" 
  12.  
  13. onClick="total(this.form,<%=(EquiptRS_total)%>)" value="<%= 
  14.  
  15. FormatNumber((EquiptRS.Fields.Item("day1").Value), 2, -2, -2, -2) %>" />
  16.         <%= FormatNumber((EquiptRS.Fields.Item("day1").Value), 2, -2, -2, -2) %>
  17. </td>
  18.  
  19. This creates an array from the EquipmentID and RS RecordCount from the database
  20.  
  21. Can I use id="DifferentName" to name="price[andgeneratedname]"? do i use GetElementByID to 
  22.  
  23. check if the element is checked or not?
  24. If I name all "name" elements the same I get NaN in the subtotals;
  25. Here is my code:
  26.  
  27. <SCRIPT LANGUAGE="JavaScript" type="text/javascript">
  28. //-->
  29. function roundoff(amount) {
  30. return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == 
  31.  
  32. Math.floor(amount*10)) ? amount + '0' : amount);
  33. }
  34.  
  35. function total(what,number) {
  36. var grandTotal = 0;
  37.  
  38. for (var i=0;i<number;i++) {
  39. if (what.elements['price' + i].checked)
  40. what.elements['price' + i].checked;
  41.  
  42.  
  43. what.elements['subtotal' + i].value=roundoff((what.elements['quantity' + i].value - 0) * 
  44.  
  45. (what.elements['price' + i].value - 0));
  46. if (what.elements['quantity' + i].value == "0")
  47. what.elements['subtotal' + i].value = "0.00";
  48.  
  49. subtotal=roundoff(what.elements['subtotal' + i].value)
  50. grandTotal += (what.elements['price' + i].value - 0) * (what.elements['quantity' + i].value 
  51.  
  52. - 0);
  53.  
  54. }
  55. //write the totals into the what.elements
  56. what.subtotal = roundoff(Math.round(subtotal*Math.pow(10,2))/Math.pow(10,2));
  57. what.grandTotal.value = roundoff(Math.round(grandTotal*Math.pow(10,2))/Math.pow(10,2));
  58.  
  59. }
  60. </SCRIPT>
  61.  
  62. Here is the HTML generated from the database:
  63.  
  64. <form id="addrange" name="addrange">
  65. <table width="100%" border="0" cellpadding="3">
  66.   <tr>
  67.  
  68.     <td width="19%">&nbsp;</td>
  69.     <td width="4%">Qty</td>
  70.     <td width="9%">1 Day    </td>
  71.     <td width="9%">2 Days    </td>
  72.     <td width="9%">3 Days</td>
  73.     <td width="9%">4 Days </td>
  74.     <td width="10%">5 Days </td>
  75.  
  76.     <td width="10%">6 Days</td>
  77.     <td width="9%">6+Days </td>
  78.     <td width="12%">subtotal</td>
  79.   </tr>
  80.  
  81.   <tr>
  82.     <td>Standard carving ski        </td>
  83.     <td><input name="quantity0" type="text" id="quantity0" value="1.00" size="2" /></td>
  84.     <td><input name="price0" id="pr1" type="radio" onclick="total(this.form,10)" 
  85.  
  86. value="8.50" />
  87.  
  88.         8.50</td>
  89.     <td><input name="price0" id="pr2" type="radio" onclick="total(this.form,10)" 
  90.  
  91. value="16.00"  />
  92.         16.00</td>
  93.     <td><input name="price0" id="pr3" type="radio" value="23.00" 
  94.  
  95. onclick="total(this.form,10)" />
  96.         23.00</td>
  97.     <td><input name="price0" id="pr4" type="radio" value="30.00" 
  98.  
  99. onclick="total(this.form,10)" />
  100.         30.00</td>
  101.  
  102.     <td><input name="price0" id="pr5" type="radio" value="37.00" 
  103.  
  104. onclick="total(this.form,10)" />
  105.         37.00</td>
  106.     <td><input name="price0" id="pr6" type="radio" value="42.00" 
  107.  
  108. onclick="total(this.form,10)" />
  109.         42.00</td>
  110.     <td>7.00</td>
  111.     <td><input name="subtotal0" type="text" id="subtotal0" value="0.00" size="5" /></td>
  112.   </tr>
  113.  
  114.  
  115.   <tr>
  116.     <td>Snow blade        </td>
  117.     <td><input name="quantity1" type="text" id="quantity1" value="1.00" size="2" /></td>
  118.     <td><input name="price1" id="pr1" type="radio" onclick="total(this.form,10)" 
  119.  
  120. value="8.50" />
  121.         8.50</td>
  122.     <td><input name="price1" id="pr2" type="radio" onclick="total(this.form,10)" 
  123.  
  124. value="16.00"  />
  125.         16.00</td>
  126.     <td><input name="price1" id="pr3" type="radio" value="23.00" 
  127.  
  128. onclick="total(this.form,10)" />
  129.  
  130.         23.00</td>
  131.     <td><input name="price1" id="pr4" type="radio" value="30.00" 
  132.  
  133. onclick="total(this.form,10)" />
  134.         30.00</td>
  135.     <td><input name="price1" id="pr5" type="radio" value="37.00" 
  136.  
  137. onclick="total(this.form,10)" />
  138.         37.00</td>
  139.     <td><input name="price1" id="pr6" type="radio" value="42.00" 
  140.  
  141. onclick="total(this.form,10)" />
  142.         42.00</td>
  143.  
  144.     <td>7.00</td>
  145.     <td><input name="subtotal1" type="text" id="subtotal1" value="0.00" size="5" /></td>
  146.   </tr>
  147.  
  148.   <tr>
  149.     <td>Superior carving ski        </td>
  150.     <td><input name="quantity2" type="text" id="quantity2" value="1.00" size="2" /></td>
  151.     <td><input name="price2" id="pr1" type="radio" onclick="total(this.form,10)" 
  152.  
  153. value="14.00" />
  154.         14.00</td>
  155.  
  156.     <td><input name="price2" id="pr2" type="radio" onclick="total(this.form,10)" 
  157.  
  158. value="27.00"  />
  159.         27.00</td>
  160.     <td><input name="price2" id="pr3" type="radio" value="36.50" 
  161.  
  162. onclick="total(this.form,10)" />
  163.         36.50</td>
  164.     <td><input name="price2" id="pr4" type="radio" value="46.50" 
  165.  
  166. onclick="total(this.form,10)" />
  167.         46.50</td>
  168.     <td><input name="price2" id="pr5" type="radio" value="55.00" 
  169.  
  170. onclick="total(this.form,10)" />
  171.  
  172.         55.00</td>
  173.     <td><input name="price2" id="pr6" type="radio" value="63.00" 
  174.  
  175. onclick="total(this.form,10)" />
  176.         63.00</td>
  177.     <td>10.50</td>
  178.     <td><input name="subtotal2" type="text" id="subtotal2" value="0.00" size="5" /></td>
  179.   </tr></table></form>
  180.  
In order for the radio buttons to work I name the buttons in their groups (6 buttons) the

same, but then all subtotals show NAN.
If I uniquely name the radio buttons (but interestingly leave the last one as is) the result

in that rows subtotal box returns the last ones value correctly,but then the radio buttons

dont work correctly.



Hope you can help.
Oct 26 '06 #1
1 6750
iam_clint
1,208 Expert 1GB
you can give each one a unique ID and request it by document.getElementById("id")
Oct 26 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: ...
6
by: Andy | last post by:
I'm not sure why my checkbox code is not working as per intended. It always keeps saying "Please select the department" even though I check the...
10
by: Marshall Dudley | last post by:
I am wanting to deteremine which radio button is selected on a form and am using: //alert(document.CC.Ecom_Payment_Card_Type.length) for (var...
3
by: Amelyan | last post by:
When we want radio button to belong to a group name we say, radio1.GroupName="GroupA". In this case, radio1 will be unselected if another radio...
1
by: number1.email | last post by:
Hello, I have a simple Web Page Questionairre in which questions are read from a database, and the user can indicate the correct answer via either...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at...
4
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the...
5
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.