Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

  1.  permalink
    Hello everybody,
    The solution I am looking for will most likely be in JavaScript. Here's what I need to do: I have an input field where users can input the quantity of an item they would like to purchase. I would then like this little script to instantly take the inputed value, multiply it by the item price and then spit out the total price right next to the original input field. All this needs to happen real-time as they are inputting the quantity. Any ideas of how I should go about this would be much appreciated.Thanks!
    • CommentAuthorMatt
    • CommentTimeMar 23rd 2007
     permalink
  2.  permalink
    Thanks, based upon that I used something like this:

    Javascript:

    function CalcPrice(){
    document.getElementsByName("quantity").length>0
    document.getElementById("purchase").quantity.value=document.getElementById("purchase").price.value / .02;
    }

    HTML:
    <form id="purchase"><input type="hidden" name="phpMyAdmin" value="4594f30712f4fabaff6997416810f3f2" />
    <input type="text" name="price" onkeyup="CalcPrice()" />
    <input type="text" name="quantity" readonly="readonly" />
    </form>
    • CommentAuthorPettyRider
    • CommentTimeMar 24th 2007
     permalink
    To follow the principal of progressive enhancement, you could remove the inline "onkeyup" attribute and append in at window.onload. Also, you could insert the "price" input field via JavaScript (actually the "quantity" field in your code. Looks like you get 'em backward).
Add your comments
    Username Password
  • Format comments as (Help)