I would like to be able to take data stored in a cookie and insert it into a hidden form value.
I am storing the data in a cookie using the following:
<script type="text/javascript">
$(function () {
$("#btnCookie").bind("click", function () {
$.cookie("name", $("#txtName").val());
I am able to retrieve the value as plain text on the next page using:
$.cookie("name")
I have a form on the 2nd page that I want this value to be a part of. How can I insert it into the following:
<input type="hidden" name="cookie" />
I have tried this but it doesn't work:
<input type="hidden" name="cookie" value="$.cookie("name")" />
I would like to be able to take data stored in a cookie and insert it into a hidden form value.
I am storing the data in a cookie using the following:
<script type="text/javascript">
$(function () {
$("#btnCookie").bind("click", function () {
$.cookie("name", $("#txtName").val());
I am able to retrieve the value as plain text on the next page using:
$.cookie("name")
I have a form on the 2nd page that I want this value to be a part of. How can I insert it into the following:
<input type="hidden" name="cookie" />
I have tried this but it doesn't work:
<input type="hidden" name="cookie" value="$.cookie("name")" />
Share
Improve this question
asked Jul 1, 2014 at 1:34
BlueRiver89BlueRiver89
771 silver badge10 bronze badges
3 Answers
Reset to default 5You can do it like this,
var cookie_val = $.cookie("name");
$('input[name=cookie]').val(cookie_val);
<input type="hidden" name="cookie" value="$.cookie('name')" />
The double quotes are causing an error in the HTML.
Try this jquery cookie u can use in php.
value="<?php echo $_COOKIE['name']; ?>"
or use jquery
$('input[name=cookie]').val($.cookie("name"));