trying to retrieve input element's value, but get empty string

107 Views Asked by At

I try to get the value of this element:

<input type=​"number" class=​"numeric float required form-control input-short"
    data-model-attribute=​"price" id=​"pin_price" max=​"10000" min=​"1.0"
    name=​"pin[price]​" step=​"0.1" value=​"1.00" data-validate=​"true" />

It has "1.0-" value after user input.

I try to retrieve its value, but got empty string back

$("#pin_price").val()

it works for input "2.0" btw

2

There are 2 best solutions below

0
mahesh On BEST ANSWER

If you inspect your code in browser you can see unwanted characters , Thats why its not working, I have modified your code and its working great with jquery. Check jsfiddle

0
user63762453 On

you can use : document.getElementById("pin_price").value

if that solves your problem. I wrote a code for you if this is what you need:

<html>


<script>
  function get()
  {
    var x=document.getElementById('pin_price').value;
    document.write("Pin price="+x);
  }
</script>
 <form>
  <input class="numeric float required form-control input-short" data-model-attribute="price"   id="pin_price" max="10000" min="1.0" name="pin[price]" step="0.1" type="number" value="1.00" data-validate="true">
  <input type="button" onclick="get()" value="ok"/>
  </html>

hope that helps.

you should have posted some more code plus there was a '?' kind of thing when I copy pasted your code.