javascript - JQuery inside PHP page -
our inventory web page written in php else. trying put jquery call webpage make description appear whenever scans barcode. working when test on jsbin.com having trouble getting run in wild. jquery src parts in footer before /body. doesn't seem wrapped ?php tags didn't put in echos.
</form> <script src="http://code.jquery.com/jquery-latest.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script> <script src="inventory.js"></script> </body> the problem may in javascript though.
var barcodes ={ "000-091-m”:”hardware - mini gender changer male male", "000-092-m”:”hardware - mini gender change female female", "000-dvi-ff”:”hardware - dual link dvi-i female female coupler adapter", }; $("textarea[id=details1]").on("input", function(){ //on value changed this.value; //text in textarea details $("textarea[id=description1]").text(barcodes[this.value]); //lookup barcode , return description description1 }); the html part affects be
<td><textarea id="quantity1" name="quantity1" cols="2" rows="1"></textarea></td> <td><textarea id="details1" name="details1" cols="25" rows="1"></textarea></td> <td><textarea id="description1" name="description1" cols="35" rows="1"></textarea></td> <td><textarea id="message1" name="message1" cols="35" rows="1"></textarea></td> when scan barcode details1 should auto populate description1 description.
what have done wrong?
without seeing html can't sure should like
$("#details1").change(function(){ //on value changed //text in textarea details $("#description1").text(barcodes[$("#details1").val()]); //lookup barcode , return description description1 }); the first argument of .on should type of event you're expecting. .change() looks change event. while there input event, this thread has pretty warning why not use it. change typically best event bind to
edit
ok, based on comments sounds use php populate fields on page load. if that, js won't trigger events. need trigger js function on page load (another solution load via ajax)
$(document).ready(function () { var val = $("#details1").val(); if(val !== '') $("#description1").text(barcodes[val]); });
Comments
Post a Comment