最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I insert a cookie data value into a hidden form field? - Stack Overflow

programmeradmin5浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 5

You 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"));
发布评论

评论列表(0)

  1. 暂无评论