Results 1 to 4 of 4

Thread: someone please help me!

  1. #1
    Join Date
    Jun 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default someone please help me!

    i need help with a couple of functions ive been working on please help me post a reply or mail me at marquisant@mail.com

    is their anything wrong with these?

    <SCRIPT>
    function calctotal() {
    var x=500;
    if (document.nick.radio1[1].checked==true)
    x=x+125;
    if (document.nick.radio2[1].checked==true)
    x=x+100;
    if (document.nick.radio3[1].checked==true)
    x=x+50;
    document.nick.totalfield.value=x;
    }

    function Check_Data() {
    if(document.nick.radio1[1].checked==true)
    if(document.nick.radio2[1].checked==true)
    if(document.nick.radio3[1].checked==true) {
    alert("Form Completed Successfully");
    return true;
    } else {
    alert("You Have not made a upgraded selection do u wish to continue?");
    return false;
    }
    }

    </SCRIPT>

    also their are 2 buttons that are used for these to functions one is submit and one is calculate total but i cant figure out how to calculate the total what am i missing? also when i click the submit button the alerts dont show up please help me id appreciate it a lot!

  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

    Your second one might work better like this:

    Code:
    function Check_Data() {
    if(document.nick.radio1[1].checked==true){
    if(document.nick.radio2[1].checked==true){
    if(document.nick.radio3[1].checked==true){
    alert("Form Completed Successfully");
    return true;
    } else {
    alert("You Have not made a upgraded selection do u wish to continue?");
    return false;
    }
    }
    }
    }
    Not sure, I would have to test it.
    - John
    ________________________

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

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by nick120
    function calctotal() {
    var x=500;
    if (document.nick.radio1[1].checked==true)
    x=x+125;
    if (document.nick.radio2[1].checked==true)
    x=x+100;
    if (document.nick.radio3[1].checked==true)
    x=x+50;
    document.nick.totalfield.value=x;
    }
    This can be simplified slightly:

    Code:
    function calcTotal() {
      var x = 500,
          e = document.forms.nick.elements;
    
      if(e.radio1[1].checked) {x += 125;}
      if(e.radio2[1].checked) {x += 100;}
      if(e.radio3[1].checked) {x += 50;}
    
      e.totalfield.value = x;
    }
    function Check_Data() {
    if(document.nick.radio1[1].checked==true)
    if(document.nick.radio2[1].checked==true)
    if(document.nick.radio3[1].checked==true) {
    alert("Form Completed Successfully");
    return true;
    } else {
    alert("You Have not made a upgraded selection do u wish to continue?");
    return false;
    }
    }
    It seems that you're trying to check that one of them is selected. If you add the appropriate braces, you'll see that this isn't the case:

    Code:
    function checkData() {
      var e = document.forms.nick.elements;
    
      if(e.radio1[1].checked) {
        if(e.radio2[1].checked) {
          if(e.radio3[1].checked) {
            return true;
          } else {
            alert('Please made a selection before continuing.');
            return false;
          }
        }
      }
    }
    What you're probably looking for is:

    Code:
    function checkData() {
      var e = document.forms.nick.elements;
    
      if(e.radio1[1].checked || e.radio2[1].checked || e.radio3[1].checked) {
        return true;
      } else {
        alert('Please made a selection before continuing.');
        return false;
      }
    }
    i cant figure out how to calculate the total what am i missing?
    You haven't shown what you're trying to total, so any suggestions would nothing beyond guesses. Please post a URL to an example of what you're trying to do.

    Mike

  4. #4
    Join Date
    Jun 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help meee!

    srry its so long

    ok here is my problem i have a form that has a couple fields and each field has a money value radio buttons have sertain values and lists have other values

    here is the form-- if u put this in the body u can see what it looks like.

    <form action="" method="post" name="nick" id="nick">
    <div align="center">
    <p>&nbsp;</p>
    <table width="100%" border="0" cellspacing="2" cellpadding="2">
    <tr>
    <td width="46%" height="24">Processor Speed </td>
    <td width="54%"><input type="radio" name="radio1" value="radiobutton">
    1000 Mhz
    <input type="radio" name="radio1" value="125">
    1800 Mhz add 125$</td>
    </tr>
    <tr>
    <td height="24">Hard Drive</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Memory </td>
    <td><select name="memory" size="1" id="memory">
    <option selected>128 MB</option>
    <option>256 MB add 80$</option>
    <option>512 MB add 125$</option>
    <option>1 GB add 175$</option>
    <option>2 GB add 225$</option>
    </select></td>
    </tr>
    <tr>
    <td>Monitor</td>
    <td><select name="monitor" size="1" id="monitor">
    <option>15” Std </option>
    <option>19” add $75</option>
    <option>21” add $125</option>
    <option selected>5” Flat add $200</option>
    <option>17” Flat add $300</option>
    </select></td>
    </tr>
    <tr>
    <td height="24">Dvd</td>
    <td><input name="radio2" type="radio" value="radiobutton">
    Dvd/Rom
    <input type="radio" name="radio2" value="100">
    Dvd/Rw add $100 </td>
    </tr>
    <tr>
    <td>3.5 inch disk drive</td>
    <td><input type="radio" name="radio3" value="50">
    Add 50$</td>
    </tr>
    <tr>
    <td height="28"> <input name="SumTotal" type="button" id="SumTotal" value="Calculate Total" onClick="calctotal()" ></td>
    <td>
    <input name="totalfield" type="text" id="totalfield" size="6"></td>
    </tr>
    <tr>
    <td> <div align="left">
    <input type="submit" name="Submit" value="Submit">
    </div></td>
    <td> <div align="left">
    <input type="reset" name="Submit2" value="Reload">
    </div></td>
    </tr>
    </table>
    <p>&nbsp;</p>
    </div>
    </form>


    basically i need to use those other 2 functions to make this form add the total of anything clicked on (radio button, lists) and on the calculate button its suppose to add 500 dollers as a base price (with no upgrades selected)
    and if any upgrade is checked or clicked on in a list it is suppose to add it to the total field by pushing calculate total. then on the submit button it should have 2 options 1 if user makes no upgrade and no choice then it alerts them and says u have not made a choice and the page refreshes or 2 the user makes a choice and hits the calculate button and then the submit button and alert thank u for your purchase. thats what it should do but i cant figure out the problem

    thank u in advance

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
  •