locked
reading cookie and assign it to default selection RRS feed

  • Question

  • User1416480938 posted

    I have the following code where the second statement works hardcoded but the first with the cookie doesn't. I know the cookie exists. What is wrong here? Thanks in advance.

    $("#State").val([cookie('MapParameters.State')]);
    // $("#State").val(["AR"]);

    Saturday, January 6, 2018 11:24 PM

Answers

  • User475983607 posted

    MapParameters.State is the cookie that I wrote and I can see with ASP.net. This is a syntax issue of assigning the state value as the selected value in a dropdown list.....

    This syntax does not look correct.

    $("#State").val([cookie('MapParameters.State')]);

    Are you using a 3rd party JQuery Cookie API?  ifso, I assume the syntax would look more like this...

    $("#State").val(cookie('MapParameters.State'));

    Can you post all the relevant code?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 7, 2018 4:24 PM

All replies

  • User475983607 posted

    I have the following code where the second statement works hardcoded but the first with the cookie doesn't. I know the cookie exists. What is wrong here? Thanks in advance.

    $("#State").val([cookie('MapParameters.State')]);
    // $("#State").val(["AR"]);

    cookie("something") suggests that you are using a 3rd party API?  Are you seeing errors in the browser dev tool console (F12)? Have you verified the cookie exists by looking at the network tab in dev tools? Did you create a cookie on the server that is visible on the client?  

    Can you explain what you are trying to do at a high level rather than how you think the problem should be solved?  Also can you post the relevant bit of code?  For example, where the cookie is being set.

    Sunday, January 7, 2018 1:51 PM
  • User1416480938 posted

    MapParameters.State is the cookie that I wrote and I can see with ASP.net. This is a syntax issue of assigning the state value as the selected value in a dropdown list.....

    Sunday, January 7, 2018 3:55 PM
  • User475983607 posted

    MapParameters.State is the cookie that I wrote and I can see with ASP.net. This is a syntax issue of assigning the state value as the selected value in a dropdown list.....

    This syntax does not look correct.

    $("#State").val([cookie('MapParameters.State')]);

    Are you using a 3rd party JQuery Cookie API?  ifso, I assume the syntax would look more like this...

    $("#State").val(cookie('MapParameters.State'));

    Can you post all the relevant code?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 7, 2018 4:24 PM