Unable to create a variable in javascript -
i creating app tell price of product when barcode scanned. basically, when barcode scanned, goes text field, , based on barcode is, textarea have price put via javascript. i've gotten work, can't seem create variable save me looking through tons of code later on.
here javascript:
function showprice() { var userinput = document.getelementbyid('barcode').value; var price = document.getelementbyid('textarea').innerhtml; if (userinput === "783466209834") { price = "16.99"; } else { price = "not valid barcode"; } } and here html:
<input type="text" name="text" class="textinput" id="barcode"> <input type="button" onclick="showprice()" value="submit"> <textarea name="" cols="" rows="" readonly="readonly" id="textarea"></textarea> right now, code isn't working, if remove
var price = document.getelementbyid('textarea').innerhtml; and replace "price" in if statement respectively, works. i'm not sure why can't create price variable.
because you're storing value of innerhtml variable, not storing reference it.
change var textarea = document.getelementbyid('textarea'); , textarea.innerhtml = "16.99" , on.
Comments
Post a Comment