• UVH713

    (@uvh713)


    I’m hope someone can help me set up JavaScript for us one page in WordPress.
    I’d like to automatically generate the values of the following:
    Total for Attendee Reservations – (Sum of number of attendees multiplied by option value) (example: 4*$75= $300)
    Total – (sum of reservation total & additional donation)
    What Javascript code do I need and can I put it directly into the page? I saw somewhere that it might be better to create a custom fields with the javascript code. Any help would be much appreciated!

    Here is the code:

    <table width="600" border="0" cellspacing="5" cellpadding="5">
          <tbody>
            <tr>
              <td align="right" width="213"></td>
              <td width="719"><strong>Reservations</strong></td>
            </tr>
            <tr>
              <td>Number of Attendees</td><td><select name="Quantity1" id="Quantity1">
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2" selected>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>
    </select>
    </td><td>
    <input id="ItemID1" type="hidden" name="ItemID1" value="1" />
    <input id="ItemName1" type="hidden" name="ItemName1" value="Adult Ticket" />
    <input id="UnitPrice1" type="hidden" name="UnitPrice1" value="75" />
    <input id="UnitDeductible1" type="hidden" name="UnitDeductible1" value="100%" /></td>
            </tr>
            <tr>
              <td align="right">Total for Attendee Reservations</td> <td> Sum of number of attendees multiplied by option value) (example: 4*$75= $300)<td> </tr>
    
            <tr>
              <td align="right" width="213">Additional Donation</td>
              <td><input id="UnitPrice2" type="text" name="UnitPrice2" size="5" />
              <input id="Quantity2" type="hidden" name="Quantity2" size="5" value="1" />
              <input id="ItemID2" type="hidden" name="ItemID2" value="2" />
              <input id="ItemName2" type="hidden" name="ItemName2" value="Donation" />
              <input id="UnitDeductible2" type="hidden" name="UnitDeductible2" value="100%" /></td>
            </tr>
            <tr> <td align="right">Total</td> <td> (sum of reservation total & additional donation)</td></tr>
    
     </table>

Viewing 2 replies - 1 through 2 (of 2 total)
  • catacaustic

    (@catacaustic)

    I don’t have the time to do all of the JavaScript for oyu, but this is an example of where to start and you should be able to extend this by studying what’s going on.

    jQuery (document).ready (function () {
        var total = jQuery ("#UitPrice1").val () * jQuery ("Quantity1").val ();
        jQuery ("#total_id").html ("$" + total.toFixed (2));
    });

    I don’t think that this does everything that you need it to, but it’s a starting point.

    As to how to add it to yor page, if it’s just a single page you can add this as part of a template, or set up a new template file to be included when that page is displayed. You can also set up a wp_enqueue_script() to include it on an external file that page. There’s a fair few ways to do this.

    Saravanan

    (@saravanan-saran)

    I’m new to wordpress.. I added some javascript in my header.php, it is working on home page. But it is not working on other pages.. I seek help to proceed further

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add JavaScript to one page in WordPress’ is closed to new replies.