Testy
Testy

Reputation: 301

How to get value from a readonly input with jQuery

Supposing I have this input:

<input type="text" name="myInput" readonly>

How to get value from a readonly input with jQuery please ?

Thanks.

Upvotes: 1

Views: 5802

Answers (2)

Deepak A
Deepak A

Reputation: 1636

You could simple use the selector for getting the value.In this solution i used name selector myInput.Hope this helps,thanks

var val = $( "input[name='myInput']" ).val() //Getting value using jquery name selector
console.log(val)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" name="myInput"  value="test" readonly>

Upvotes: 0

Shinjo
Shinjo

Reputation: 693

As usual, just select the element and get the value: $(":input[type=text][readonly='readonly']").val()

$(":input[type=text][readonly='readonly']").val('testvalue');

console.log($(":input[type=text][readonly='readonly']").val());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" name="myInput" readonly>

Upvotes: 2

Related Questions