javascript - how to set textbox value in jquery -
how load value textbox using jquery?tried 1 below [object object]
output. please enlighten me on this, i'm new jquery.
proc = function(x,y) { var str1 = $('#pid').value; var str2 = $('#qtytobuy').value; var str3= $('#subtotal').load('compz.php?prodid=' + x + '&qbuys=' + y); $('#subtotal').val(str3); }
and here's html form:
<form name="yoh" method="get"> product id: <input type="text" name="pid" value=""><br/> quantity buy:<input type="text" name="qtytobuy" value="" onkeyup="proc(document.yoh.pid.value, this.value);"></br> subtotal:<input type="text" name="subtotal" id="subtotal" value=""></br> <div id="compz"></div> </form>
i think want set response of call url 'compz.php?prodid=' + x + '&qbuys=' + y
value of textbox right? if so, have like:
$.get('compz.php?prodid=' + x + '&qbuys=' + y, function(data) { $('#subtotal').val(data); });
reference: get()
you have 2 errors in code:
load()
puts html returned ajax specified element:load data server , place returned html matched element.
you cannot set value of textbox method.
$(selector).load()
returns jquery object. default object converted[object object]
when treated string.
further clarification:
assuming url returns 5
.
if html looks like:
<div id="foo"></div>
then result of
$('#foo').load('/your/url');
will be
<div id="foo">5</div>
but in code, have input element. theoretically (it not valid html , not work noticed), equivalent call result in
<input id="foo">5</input>
but need
<input id="foo" value="5" />
therefore, cannot use load()
. have use method, response , set value yourself.
Comments
Post a Comment