Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
101
rated 0 times [  105] [ 4]  / answers: 1 / hits: 115029  / 14 Years ago, tue, august 10, 2010, 12:00:00

I was wondering if it's possible to store the return json in a hidden input field. For example this is what my json return:



[{id:15aea3fa,firstname:John,lastname:Doe}]


I would like to just store the id in a hidden field so I can reference it later to do something with it.



Example: I have something like this:



<input id=HiddenForId type=hidden value= />


and would like jquery to return the value later to me like so:



var scheduletimeid = $('#HiddenForId').val();

More From » jquery

 Answers
235

You can store it in a hidden field, OR store it in a javascript object (my preference) as the likely access will be via javascript.



NOTE: since you have an array, this would then be accessed as myvariable[0] for the first element (as you have it).



EDIT show example:



clip...
success: function(msg)
{
LoadProviders(msg);
},
...

var myvariable =;

function LoadProviders(jdata)
{
myvariable = jdata;
};
alert(myvariable[0].id);// shows 15aea3fa in the alert


EDIT: Created this page:http://jsfiddle.net/GNyQn/ to demonstrate the above. This example makes the assumption that you have already properly returned your named string values in the array and simply need to store it per OP question. In the example, I also put the values of the first array returned (per OP example) into a div as text.



I am not sure why this has been viewed as complex as I see no simpler way to handle these strings in this array.


[#95973] Friday, August 6, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aidan

Total Points: 72
Total Questions: 95
Total Answers: 121

Location: Uzbekistan
Member since Sat, Feb 27, 2021
3 Years ago
aidan questions
Mon, Oct 11, 21, 00:00, 3 Years ago
Wed, Sep 29, 21, 00:00, 3 Years ago
Sun, Sep 5, 21, 00:00, 3 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;