How do i go about emptying the values of textboxes here is below code i h've worked out but doesn't seem to work
var txtName = $("input#txtName"),txtPrice = $("input#txtPrice");
$(txtName,txtPrice).val("");
$([txtName,txtPrice]).val("");
I Put them in variables as these are used further in the script.
Here is a few ways to do it;
txtName.add(txtPrice).val("");
// OR
$("input#txtName,input#txtPrice").val("");
(There is a $
sign in your txtPrice
input by the way.)
First Method didn't work because it's a way of using jQuery selector. When you use jQuery like that first parameter will be the selector and second will be the container object where the selector works. Basically it's almost same thing like this;
$(txtPrice).find(txtName).val("");
Because there is no txtName
in txtPrice
neither value will be emptied.
Second Method works because you're giving your parameters as an array to jQuery selector. It accepts it and does .val()
action to every element of array. This way is legit but because your variables already jQuery objects there is no need to use this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With