Results 1 to 2 of 2

Thread: checkbox addition/subtraction

  1. #1
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default checkbox addition/subtraction

    i've got a checkbox what i want it to do when it is checked is to add 10.00 to a text field and when it is unchecked it subtracts 10.00
    what i've got so far is:

    <script language="JavaScript"><!--
    function calculate(what) {
    what.answer.value =0;
    for (var i=0,answer=0;i<1;i++)
    answer += (what.elements['Checkbox' + i].checked)&(what.elements['Checkbox' + i].value-'10.00');
    what.answer.value = answer;
    }
    //--></script>

    <form ID="Form2">
    <INPUT type="checkbox" ID="Checkbox0" NAME="Checkbox0" VALUE="1"
    onclick="calculate(this.form)">
    <input type="text" name="answer" ID="Text13">
    </form>

    if i click on the checkbox it only adds 1 to the text field T_T
    any help would be greatly appreciated

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <script type="text/javascript">
    <!--
    function calculate(what) {
    if (Math.abs(what.answer.value)!==Math.abs(what.answer.value)){
    alert ('Numbers Only Please!')
    return;
    }
    what.answer.value = (what.elements['Checkbox0'].checked)? parseInt(what.answer.value, 10)-10 : parseInt(what.answer.value, 10)+10;
    }
    //-->
    </script>
    
    <form>
    <input type="checkbox" name="Checkbox0" onclick="calculate(this.form)">
    <input type="text" name="answer" value="0">
    </form>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •