Web Analytics Made Easy -
StatCounter Array Question - CodingForum

Announcement

Collapse
No announcement yet.

Array Question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Array Question

    Could someone please tell me where I am going wrong with the following :-

    function CalcPrice(form) {
    var a=(form.lstmemtype.options[form.lstmemtype.selectedIndex].value)
    var b=(form.lstmemterm.options[form.lstmemterm.selectedIndex].value)
    var c=[0,0,120,340,550,950,70,160,320,550,40,100,180,350]
    var d = a+b
    form.txtprice.value="£" + d
    }

    There is 3 values in A - 1,5,9
    There is 4 values in B - 1,2,3,4

    I want to add A+B together and insert the corresponding value from array c into form.txtprice.value also adding the "£" sign to the beginning.

    If I am doing this the wrong way could someone please point me in the right direction.

    Many Thanks,


    SRThomson

  • #2
    Please try the following


    function CalcPrice(form) {
    var a=(form.lstmemtype.options[form.lstmemtype.selectedIndex].value)
    var b=(form.lstmemterm.options[form.lstmemterm.selectedIndex].value)
    var c=[0,0,120,340,550,950,70,160,320,550,40,100,180,350]
    var d = (a*1)+(b*1)
    form.txtprice.value="£" + c[d]
    }
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

    Comment


    • #3
      I have tried the code you wrote.

      But all I am getting is Error : 'lstmemtype' is null or not an object

      Any ideas?

      Comment


      • #4
        If this helps here is a copy of the complete page :-

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <title>Untitled</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <script language="JavaScript" type="text/JavaScript">
        <!--




        function CalcPrice(form) {
        var a=(form.lstmemtype.options[form.lstmemtype.selectedIndex].value)
        var b=(form.lstmemterm.options[form.lstmemterm.selectedIndex].value)
        var c=[0,0,120,340,550,950,70,160,320,550,40,100,180,350]
        var d= (a*1)+(b*1)
        form.txtprice.value="£" +c[d]
        }
        function MM_reloadPage(init) { //reloads the window if Nav4 resized
        if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
        else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
        }
        MM_reloadPage(true);

        function MM_callJS(jsStr) { //v2.0
        return eval(jsStr)
        }
        //-->
        </script>
        <style type="text/css">
        <!--
        body {
        background-color: #000000;
        }
        .style23 {color: #FFFFFF}
        .style26 {font-size: 10px}
        .style30 {font-family: Geneva, Arial, Helvetica, sans-serif}
        body,td,th {
        font-family: Arial, Helvetica, sans-serif;
        }
        .style32 {color: #FFFFFF; font-size: 9px; }
        .style33 {font-size: 9px}
        .style41 {color: #FFFFFF; font-size: 10px; font-family: Geneva, Arial, Helvetica, sans-serif; }
        .style37 {font-family: Arial, Helvetica, sans-serif}
        .style38 {color: #FFFFFF; font-size: 10px; font-family: Arial, Helvetica, sans-serif; }
        .style42 {
        font-size: 12px;
        font-weight: bold;
        font-style: italic;
        }
        .style43 {font-size: 12px}
        .style44 {color: #FFFFFF; font-size: 10px; }
        .style45 {font-weight: bold}
        .style46 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; }
        .style47 {color: #FFFFFF; font-size: 10px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; }
        -->
        </style>
        </head>

        <body>
        <div id="body" style="position:absolute; left:0px; top:5px; width:670px; height:500px; z-index:3">
        <table width="670" border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td width="90">&nbsp;</td>
        <td width="580">&nbsp;</td>
        </tr>
        </table>
        <table width="670" border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td width="90" height="40">&nbsp;</td>
        <td width="570" height="40" valign="bottom"><span class="style44">Please complete the following form:- </span></td>
        </tr>
        </table>
        <table width="670" border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td width="90" valign="top"><img src="images/spacer.gif" width="90" height="1"></td>
        <td width="670"><form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="frmapply" target="paypal" id="frmapply">
        <table width="580" border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td width="90"><div align="right" class="style26">
        <div align="left"><span class="style23">First Name</span></div>
        </div></td>
        <td width="5"><div align="right"><span class="style23"> </span></div></td>
        <td width="260"><input name="txtfirstname" type="text" id="txtfirstname2"></td>
        </tr>
        <tr>
        <td width="90"><div align="right" class="style32">
        <div align="left">Last Name </div>
        </div></td>
        <td width="5"><div align="right"></div></td>
        <td width="260"><input name="txtlastname" type="text" id="txtlastname2"></td>
        </tr>
        <tr>
        <td width="90"><div align="right" class="style26">
        <div align="left"><span class="style23">Email Address</span></div>
        </div></td>
        <td width="5"><div align="right"></div></td>
        <td width="260"><input name="txtemailaddress" type="text" id="txtemailaddress2"></td>
        </tr>
        <tr>
        <td width="90"><div align="right" class="style26">
        <div align="left"><span class="style23">Mobile Number</span></div>
        </div></td>
        <td width="5"><div align="right"></div></td>
        <td width="260"><input name="txtmobileno" type="text" id="txtmobileno2"></td>
        </tr>
        <tr>
        <td width="90"><div align="right" class="style26">
        <div align="left"><span class="style23">Membership Type</span></div>
        </div></td>
        <td width="5"><div align="right"></div></td>
        <td width="260"><span class="style33">
        <select name="lstmemtype" id="lstmemtype" onChange="MM_callJS('CalcPrice(this.form)')">
        <option value="5">UK</option>
        <option value="1" selected>UK Plus</option>
        <option value="9">Australian</option>
        </select>
        </span></td>
        </tr>
        <tr>
        <td width="90"><div align="right" class="style26">
        <div align="left"><span class="style23">Membership Term</span></div>
        </div></td>
        <td width="5"><div align="right"></div></td>
        <td width="260"><select name="lstmemterm" id="lstmemterm" onChange="MM_callJS('CalcPrice(this.form)')">
        <option value="1" selected>1 Month</option>
        <option value="2">3 Months</option>
        <option value="3">6 Months</option>
        <option value="4">12 Months</option>
        </select></td>
        </tr>
        <tr>
        <td width="80"><div align="right" class="style26">
        <div align="left"><span class="style23">Price</span></div>
        </div></td>
        <td width="5"><div align="right"></div></td>
        <td width="260"><input name="txtprice" type="text" id="txtprice" value="£120" maxlength="0"></td>
        </tr>
        <tr>
        <td width="80"><span class="style26"></span></td>
        <td width="5">&nbsp;</td>
        <td width="260">
        </td>
        </tr>
        <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        </table>
        </form> <p align="justify" class="style23 style26 style30">&nbsp;</p> </td>
        </tr>
        </table>
        </div>
        <script language=JavaScript>
        <!--

        //Disable right mouse click Script
        var message="Sorry this function has been removed";

        ///////////////////////////////////
        function clickIE4(){
        if (event.button==2){
        alert(message);
        return false;
        }
        }

        function clickNS4(e){
        if (document.layers||document.getElementById&&!document.all){
        if (e.which==2||e.which==3){
        alert(message);
        return false;
        }
        }
        }

        if (document.layers){
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown=clickNS4;
        }
        else if (document.all&&!document.getElementById){
        document.onmousedown=clickIE4;
        }

        document.oncontextmenu=new Function("alert(message);return false")

        // -->
        </script>
        </body>
        </html>

        Comment


        • #5
          In your opening SELECT tags you have

          onChange="MM_callJS('CalcPrice(this.form)')

          If you change it to

          onChange="CalcPrice(this.form)"

          It works


          I am a bit puzzled as to why you need this function

          function MM_callJS(jsStr) { //v2.0
          return eval(jsStr)
          }
          The silent one.

          The most dangerous thing in the world is an idea.
          The most dangerous person in the world is the one with an idea.

          Comment


          • #6
            Dreamweaver added this function when I created a behavior for the lstmemtype drop down box.

            Mr J thanks, this now works.

            Comment

            Working...
            X