1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple Javascript Form

Discussion in 'JavaScript' started by drdavisjr, Apr 6, 2008.

  1. #1
    I have a very simple issue that I need help with...

    I have a form that I want a dynamic submit button based on the values entered in a couple of select inputs.

    Here is my script:

    <script type="text/javascript" language="javascript">
    function getPrice () {
    var quantity = document.getElementById('quantity').value;
    var ad_length = document.getElementById('ad_length').value;
    if (ad_length == 1) {
    amount = 5.99;
    total = document.write('The Discounted Price For ' + quantity + ' Ads of ' + ad_length + ' Months Is $ ' + eval(quantity*amount));
    }
    else if (ad_length == 2) {
    amount = 7.49;
    total = document.write('The Discounted Price For ' + quantity + ' Ads of ' + ad_length + ' Months Is $ ' + eval(quantity*amount));
    }
    else if (ad_length == 3) {amount = 12.49;
    total = document.write('The Discounted Price For ' + quantity + ' Ads of ' + ad_length + ' Months Is $ ' + eval(quantity*amount));
    }
    else if (ad_length == 6) {amount = 14.99;
    total = document.write('The Discounted Price For ' + quantity + ' Ads of ' + ad_length + ' Months Is $ ' + eval(quantity*amount));
    }
    else if (ad_length == 12) {amount = 22.49;
    total = document.write('The Discounted Price For ' + quantity + ' Ads of ' + ad_length + ' Months Is $ ' + eval(quantity*amount));
    }
    }
    </script>

    Select #1

    <select size="1" name="HowMany" id="quantity" onChange="window.document.form.B1.value=getPrice('total');">
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20+</option>
    </select>

    Select #2

    <select size="1" name="Length" id="ad_length">
    <option value="1">1-Month</option>
    <option value="2">2-Months</option>
    <option value="3">3-Months</option>
    <option value="4">4-Months</option>
    <option value="6">6-Months</option>
    <option value="9">9-Months</option>
    <option value="12">12-Months</option>
    </select>

    And here is my submit button

    <input type="submit" name="B1" value="" style="background:url(images/prototype.png); background-repeat:no-repeat; width:446px; height:48px; border:none">

    Any help you can provide will be greatly appreciated.
     
    drdavisjr, Apr 6, 2008 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    That's rather vague; exactly what do you mean?
    document.write can only be used a build time, not after the document is loaded.
     
    Logic Ali, Apr 6, 2008 IP