1

Supposing I have this input:

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

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

Thanks.

2 Answers 2

2

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>

Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.