JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old May 26th, 2004, 12:56 PM
nmbn nmbn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 nmbn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Order form with radio buttons HELP

Hello
I have an order form with radio buttons divided into groups and when I select a button the value (price) is added into a text field. My problem is that the value keeps being added even when I select buttons from the same group. I have not been able to have the script add only once from the same group. For example if the selected button one from group one has a value of $15 and I change to button two from that same group one valued at $12 I would like it to subs tract the $15 and add $12. What should i add or change to the script to make this happen can any one help me. I am very much new to JavaScript and I am still learning so I still can't with a script from scratch. Many thanks and sorry for the length of this post.

Code:
<html>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- Original:  Paul Brino (irandd@aol.com) -->

<!-- This script and many more are available free online at -->

<!-- A SNG/RSHWeb Company http://java.searchrealm.com -->


function checkChoice(whichbox) {

with (whichbox.form) {

if (whichbox.checked == false)

hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value);

else

hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value);

return(formatCurrency(hiddentotal.value));

   }

}

function formatCurrency(num) {

<!-- Function courtesy of:  Cyanide_7 (leo7278@hotmail.com) -->

<!-- Web Site:  http://www7.ewebcity.com/cyanide7 -->

num = num.toString().replace(/\$|\,/g,'');

if(isNaN(num)) num = "0";

cents = Math.floor((num*100+0.5)%100);

num = Math.floor((num*100+0.5)/100).toString();

if(cents < 10) cents = "0" + cents;

for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)

num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));

return ("$" + num + "." + cents);

}

var topMargin = 100 
var slideTime = 1200
var ns6 = (!document.all && document.getElementById); 
var ie4 = (document.all);
var ns4 = (document.layers);
window.setInterval("main()", 10) 


</script>

<style type="text/css">
<!--
.style1 {
    color: #FFFFFF;
    font-weight: bold;
}
.style2 {color: #FF0000}
-->
</style>
</HEAD>

<BODY>

<center>

<form action="" name="myform2" id="myform2">
  <table width="133" border="0" bordercolor="#FFFFFF">
    <tr bgcolor="#00008A">
      <td colspan="3"><span class="style1">Groupe 1</span></td>
      </tr>
    <tr>
      <td width="51">1-1</td>
      <td width="48">None</td>
      <td><input name=1 type=radio onClick="this.form.total.value=checkChoice(this);" value="0" checked></td>
    </tr>
    <tr>
      <td>1-2 </td>
      <td>$12.39 </td>
      <td><input type=radio name=1 value="12.39" onClick="this.form.total.value=checkChoice(this);"></td>
    </tr>
    <tr>
      <td>1-3</td>
      <td>$18.75</td>
      <td><input type=radio name=1 value="18.75" onClick="this.form.total.value=checkChoice(this);"></td>
    </tr>
    <tr>
      <td height="3" colspan="3">&nbsp;</td>
      </tr>
    <tr bgcolor="#00008A">
      <td colspan="3"><span class="style1">Groupe 2</span></td>
      </tr>
    <tr>
      <td>2-1</td>
      <td>None</td>
      <td><input name=2 type=Radio onClick="this.form.total.value=checkChoice(this);" value="0" checked></td>
    </tr>
    <tr>
      <td>2-2</td>
      <td>$ .79</td>
      <td><input type=Radio name=2 value=".79" onClick="this.form.total.value=checkChoice(this);"></td>
    </tr>
    <tr>
      <td>2-3</td>
      <td>$ 1.75</td>
      <td><input type=Radio name=2 value="1.75" onClick="this.form.total.value=checkChoice(this);"></td>
    </tr>
    <tr>
      <td height="3" colspan="3">&nbsp;</td>
      </tr>
    <tr bgcolor="#00008A">
      <td colspan="3"><span class="style1">Groupe 3</span></td>
      </tr>
    <tr>
      <td>3-1</td>
      <td>None</td>
      <td><input name=3 type=radio onClick="this.form.total.value=checkChoice(this);" value="0" checked></td>
    </tr>
    <tr>
      <td>3-2</td>
      <td>$1.99</td>
      <td><input type=radio name=3 value="1.99" onClick="this.form.total.value=checkChoice(this);"></td>
    </tr>
    <tr>
      <td>3-3</td>
      <td>$22.75</td>
      <td><input type=radio name=3 value="22.75" onClick="this.form.total.value=checkChoice(this);"></td>
    </tr>
    <tr>
      <td height="3" colspan="3">&nbsp;</td>
      </tr>
    <tr bgcolor="#00008A">
      <td height="20" colspan="3">&nbsp;</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td height="3"><input type="submit" name="Submit" value="Send">        </td>
      <td height="3"><input name=total type=text value="$0.00" size="7" maxlength="10" readonly>
        <input type=hidden name=hiddentotal value=0></td>
      <td height="3"><input type="reset" name="Reset" value="Reset"></td>
    </tr>
  </table>
  </form>
</center>
</body>
</html>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Order form with radio buttons HELP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway