简体   繁体   中英

Change textbox value in javascript

I want to update the value of text box from where I'm getting initial value to add product to cart. Now I'm applying round function & I want to update the value of text box that is because I'm using ajax & if I'm applying round function, user must know how system calculated everything.

Here's my simple code:

<script>
$(document).ready(function(){
$(document).delegate('.purchasenow','click', function(e){
    var buynow=this;
    var productid = $(this).attr('id');
    var quantity = $('.quo_'+productid).val();
    var quantity = Math.round(quantity);
    alert(quantity); //This gives the value
    $('.quo_'+productid).value = quantity; //This is not working
});
});

Can anyone tell why it's not working? It's very simple but I'm not able to find out the cause.

Have you tried

$('.quo_'+productid).val(quantity);

The jQuery selector returns a wrapped object, not the actual DOM element. I don't think wrapped object has the .value property

you are almost correct the only thing why it is not working because your syntax is wrong

this is the correct syntax for jQuery

$('.quo_'+productid).val(quantity);

if you want it in javascript

var txt = document.getElementById("quo_"+productid);
txt.value = quantity;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM