Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Javascript problem

  • 15-02-2004 02:30PM
    #1
    Closed Accounts Posts: 126 ✭✭


    Hi guys im trying to write code that will automatically update a value in TotalPrice when the user changes the 'Amount' but I dunno how to pass the 'VALUE' into the writeIt function, heres the code
    [PHP]
    <HTML>
    <HEAD>
    <TITLE>Online store</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function writeIt(the_price, object)
    {
    var total = the_price;
    object.value = total;
    }
    -->
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM NAME="Store">
    <INPUT TYPE="TEXT" NAME="Price" VALUE="€11.99"></INPUT>
    <INPUT TYPE="TEXT" NAME="Amount" VALUE="0" onChange="writeIt('Change', Store.TotalPrice)"></INPUT>
    <TEXTAREA NAME="TotalPrice" VALUE="€0"></TEXTAREA>
    </FORM>
    </BODY>
    </HTML>
    [/PHP]


Comments

  • Closed Accounts Posts: 801 ✭✭✭dod


    I would've thought something like this:
    <script language="JavaScript">
    <!--
    function UpdateTotalPrice()
    {
    var price=document.page.the_price.value;
    document.page.Amount.value=document.page.Amount.value + price;
    }

    </script>

    Then the HTML would be something along the lines of:
    <form name="page" action="http://www.domain.com/&quot; method="get">
    <input type="text" name="the_price" onChange="UpdateTotalPrice()" class="textfield" size="5">
    <input type="text" name="Amount" class="textfield" size="8" maxlength="8">
    </form>


  • Closed Accounts Posts: 13 ter


    <HTML>
    <HEAD>
    <TITLE>Online store</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    function cal()
    {
    var price,amount,total;

    price = parseInt(document.form1.price.value);
    amount = parseInt(document.form1.amount.value);
    total = (amount*price);
    document.form1.total.value = total;
    if (document.form1.total.value =="" || document.form1.total.value == "0")
    {
    alert("please type in an amount");
    }

    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <form name="form1" method="post" action="">
    <table width="200" border="0">
    <tr>
    <td width="61">price</td>
    <td width="129"><input name="price" type="text" id="price" value="5.00"></td>
    </tr>
    <tr>
    <td>amount</td>
    <td><input name="amount" type="text" id="amount" value="0"></td>
    </tr>
    <tr>
    <td>total</td>
    <td><input name="total" type="text" id="total"></td>
    </tr>
    <tr>
    <td>calculate</td>
    <td><input type="button" name="Submit" value="Submit" onClick="cal()"></td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    </tr>
    </table>
    </form>
    </BODY>
    </HTML>


Advertisement