admin管理员组

文章数量:1323348

I have a input box like this

<input type="text" class="form-control" onblur="getProductqty('+this.value+')"
    placeholder="0" id="'+productSizeId+'">

And i am trying to get the value of the input field by the getProductqty() function.

I have tried like this

    function getProductqty(productQnty)
    {
        console.log(productQnty);
        var $this = jQuery(this);
        console.log($this.value );
    }

From the both i found the undefined value. Please any help. Thank you in advance.

I have a input box like this

<input type="text" class="form-control" onblur="getProductqty('+this.value+')"
    placeholder="0" id="'+productSizeId+'">

And i am trying to get the value of the input field by the getProductqty() function.

I have tried like this

    function getProductqty(productQnty)
    {
        console.log(productQnty);
        var $this = jQuery(this);
        console.log($this.value );
    }

From the both i found the undefined value. Please any help. Thank you in advance.

Share Improve this question edited Aug 9, 2018 at 5:57 wazz 5,0785 gold badges22 silver badges36 bronze badges asked Aug 9, 2018 at 5:54 RanjitRanjit 1,72410 gold badges30 silver badges64 bronze badges 1
  • 2 You're passing a hardcoded string as the argument. I have difficulty believing that it is ing out as undefined. (Possibly you are generating that HTML with embedded JS using PHP or something. You need to provide a real minimal reproducible example) – Quentin Commented Aug 9, 2018 at 5:58
Add a ment  | 

2 Answers 2

Reset to default 4

You can simply pass the reference this to getProductqty function and get the value of input like

function getProductqty(input){
  console.log(input.value)
}
<input type="text" class="form-control" onblur = "getProductqty(this)" placeholder="0" id="productSizeId">

You can simply pass this and get it in the function and access the value property on it. Or if you want to pass this.value then you dont need all those extra + and '

function getProductqty(value){
  console.log(value);
}
<input type="text" class="form-control" onblur = "getProductqty(this.value)" placeholder="0">

本文标签: javascriptGet the Value of input text on blurStack Overflow