Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript problem

Options
  • 15-02-2004 2: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