1

How do I get the value of the text from this input:

I am trying to get the value "Hello" for the text elemen in this input

<input id="myText" type="hidden" value="{"enabled":true,"value":"377352:0","text":"Hello","selected":false,"active":true}"/>

2 Answers 2

3

Since the value looks like a JSON string, use parseJSON method to parse it and the access the required property.

var value = $.parseJSON($('#myText').val()).text;

Refernce: $.parseJSON()

Note: In your markup the value of the input should either enclose its content in single quote or you should escape the double quotes inside the string.

Demo

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

Comments

0

With JQuery you could just ask for the element value then it is currently an object so can access via that. Something like the code below should suffice:

var value = $('#myText').val();
if (value && typeof(value) === 'object') {
    var text = value.text;
}

Text should now hold the value Hello

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.