Form scripting

Discussion in 'Software' started by Jodi, Mar 21, 2007.

  1. Jodi

    Jodi Private First Class

    I was wondering Anyone happens to be familiar with form scripting for calculations? (javaScript) I am working on a form which I need a bit of help with.
    Thank you in advance
    jo@yourpagetoday.com
     
  2. Jodi

    Jodi Private First Class

    in short, I would like to make it so that ther are three check boxes, when one is checked the other two are deacrivated and do not calcualte their total.
    here is an example of the form,
    https://www.msaasecure.com/2007ConvRegForm.htm
    the check boxes in question will be Sunday, Monday and I need to add a third that says both days, which should yield a discount when checked as eash individual day is $99, abd both days is $169 in which case when both days is checked, Sunday and Monday are deactivated.
    Thank you all in advance.
     
  3. Mada_Milty

    Mada_Milty MajorGeek

    Code:
    document.forms[x].objectname.disabled = true/false
    The above should allow you to enable/disable elements, depending on the boolean value you assign. Note that you will have to provide the index number of the form for x, and the name of the element for objectname.

    You can also RETRIEVE this value to determine which discount to use.

    for example:

     
  4. Jodi

    Jodi Private First Class

    ok so when you say which discount to use, you mean that when they check the both check both then the dicsount will take away the value of the sunday and monday box?...ok I think I get it....it would look something like this?
    }var v_disc
    if (document.forms[theForm].Monday1.disabled == false || document.forms[x].Sunday1.disabled == false) {
    v_disc = 99
    }
    else if (document.forms[theForm].SundayMonday.disabled == false) {
    v_disc = 169
    }

    but if each box is 99, then do I have to seperate out sunday from monday var??
     
  5. Jodi

    Jodi Private First Class

    For simplicity sake, I just want to make the check boxes sunday and monday disabled when both box is checked.
    Using: document.forms[x].objectname.disabled = true/false
    How do I specify that this happens when the SundayMonday box is checked?
     
  6. Kodo

    Kodo SNATCHSQUATCH

    why don't you just use a radio button for this?
    figure.. if Sunday is checked.. then it makes no sense to click Monday as well because that would mean they want both days.. in which case, they would just use the "both days" selection. And so if the "both days" option is checked, then you don't need either Sunday or Monday options..

    Radio buttons.. try it.. you'll like it! :)
     
  7. Jodi

    Jodi Private First Class

    Thank you Kodo, I really appreciate the insight, however, I am not script savvy enough to get this right. Especially with radio buttons, which is why I went with the check boxes.
    Might you be able to lend a sciripting hand?
    Thank you kindly!
    :)
     
  8. Mada_Milty

    Mada_Milty MajorGeek

    I would suggest you use the 'onclick' event of the checkbox. This would require a javascript function like this:

    Code:
    function both_click () {
         if (document.forms[x].both.value == true) {
              document.forms[x].monday.disabled = true
              document.forms[x].sunday.disabled = true
         }
         else if (document.forms[x].both.value == false) {
              document.forms[x].monday.disabled = false
              document.forms[x].sunday.disabled = false
         }
    }
    And for your checkbox, you would need something like this:

    Code:
    <input name="both" type="checkbox" onclick="both_click()"></input>
    Kodo really has a good suggestion, though... radio buttons would be no more difficult than this! You wouldn't need the disabling/enabling effects, only code to determine the discount! Heh, I kinda get tunnel vision sometimes....
     
  9. Jodi

    Jodi Private First Class

    :D Thank you
     
  10. Jodi

    Jodi Private First Class

  11. Kodo

    Kodo SNATCHSQUATCH

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
    
    <html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]" >
    <head runat="server">
        <title>Untitled Page</title>
            <script  language="javascript" type="text/javascript">
            
            function calc(day){
            switch(day){
                case "sun":
                case "mon":
                alert("99 bucks baby!");
                    break;
                case "both":
                alert("169 ..show me the money!");
                    break;
                   }
            
            }
            </script>
    
    </head>
    <body>
        <form id="form1" >
        <div>
           
            Sunday <input id="Radio1" name="day" value="sun" type="radio" onclick="calc(this.value);"/>
            Monday <input id="Radio2" name="day" value="mon" type="radio" onclick="calc(this.value);"/>
            Both Days <input id="Radio3" name="day" value="both" type="radio" onclick="calc(this.value);"/>
            
            </div>
        </form>
    </body>
    </html>
    it doesn't get much easier than that.
     
  12. Mada_Milty

    Mada_Milty MajorGeek

    Instead of document.forms[theForm].objectname.attribute try using:

    document.forms[0].objectname.attribute
     
  13. Jodi

    Jodi Private First Class

    confused No luck
     
  14. Mada_Milty

    Mada_Milty MajorGeek

    Code:
          <td align="center" valign="bottom"><input name="SundayMonday" type="checkbox" id="SundayMonday" onclick="addUp(169, 'SundayMonday')  "value="Attending" ></td>
    Your checkbox isn't calling the function! We need some event of the checkbox to call the function. Otherwise it will just sit there.
     
  15. Jodi

    Jodi Private First Class

    but we cant have two onClick functions can we?
    would it look like this:
    <td align="center" valign="bottom"><input name="SundayMonday" type="checkbox" id="SundayMonday" onclick="addUp(169, 'SundayMonday') onclick="both_click" "value="Attending" ></td>
    :)
     
  16. Mada_Milty

    Mada_Milty MajorGeek

    No, but we could use ANOTHER event, such as onchange....

    I do have to mention again that Kodo has a fairly elegant solution for you there!
     
  17. Jodi

    Jodi Private First Class

    Yes Kodo Does, but I cant write the code. =(
     
  18. Kodo

    Kodo SNATCHSQUATCH

    what code?? Jodi..
     
  19. Jodi

    Jodi Private First Class

    Ok I can create the radio buttons, and name them and all that fun stuff, but I am uncertain of how to write the scripting to make them calculate and function properly.
    You see I am more of a designer and less of a scripter, I have never had any formal training, just self taught with little things here and there, this form is the most extensive scripting that I have done to date, this seems to be where my skills come to a halt.
    I do appreaciate your help, this rookie has a ways to go, I know.
     
  20. Kodo

    Kodo SNATCHSQUATCH

    ok, well, I don't have the time to do that ;) sorry..
     
  21. Jodi

    Jodi Private First Class

    Its ok I undersatand, thanks anyway
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds