Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:54:13+00:00 2026-06-04T03:54:13+00:00

i want to set a cookie for dropdown menu in the html form ,when

  • 0

i want to set a cookie for dropdown menu in the html form ,when refresh the page i should get the value that is stored in the cookie in my drop down box.
I have written code for input box as follows:

<script type="text/javascript">
 function setCookie(c_name,value,exdays)
{

var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
</script>

<input name="order_num" type="text" size="10" value="<?php if(isset($_COOKIE["order_num"])) echo $_COOKIE["order_num"];?>" onblur="setCookie(this.name,this.value,60*60*2)" />

In the similar way i want to write the cookie for dropdown box.the code for drop down menu is
follows:

<select name="quality" onChange="setCookie('quality',this.value,60*60*2)" selected="" >
<option >Select One</option>  
<option value="good" selected="good">Good</option>
<option value="ok" selected="ok">A bit low but we can use it</option>
...

</select>

<input type="checkbox" name="proceed_opt[]" value="I will upload new Image" onblur="setCookie(this.name,this.value,60*60*2);>
         Insert Option &quot;I will upload new Image&quot;</td></tr>


         <input type="checkbox" name="proceed_opt[]" value="I approve this sample for a Night Light" onblur="setCookie(this.name,this.value,60*60*2);>
         Insert Option &quot;<font face="Arial, Helvetica, sans-serif" size="2">I approve this sample for a Night Light</font>&quot; 

any one help me to set the cookie….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:54:14+00:00Added an answer on June 4, 2026 at 3:54 am

    You should check if the cookie value equals the select item. If so, give the item the HTML selected attribute.

    $choices = array(
      'good' => 'Good',
      'ok'   => 'A bit low but we can use it'
    );
    
    <select name="quality" onChange="setCookie('quality', this.value, 60*60*2)">
      <option>Select One</option>
    
      <?php foreach ($choices as $value=>$select): ?>
    
        <option value="<?php echo $value ?>"
          <?php if(isset($_COOKIE["quality"]) && $_COOKIE["quality"] == $value): ?>
            selected="selected"
          <?php endif; ?>
        >
          <?php echo $select ?>
        </option>
    
      <?php endforeach; ?>
    
    </select>
    

    This code may need some modification because I didn’t test it. But the main idea is there.


    Edit: Example for checkboxes:

    $choices = array(
      'good' => 'Good',
      'ok'   => 'A bit low but we can use it'
    );
    
    <?php foreach ($choices as $value=>$choice): ?>
    
      <input type="checkbox" value="<?php echo $value ?>"
        onclick="setCookie('checkbox', this.value, 60*60*2)"
        <?php if(isset($_COOKIE["checkbox"]) && $_COOKIE["checkbox"] == $value): ?>
          checked="checked"
        <?php endif; ?>
      >
      <?php echo $select ?>
    
    <?php endforeach; ?>
    

    The problem with this code is that it won’t work if the user doesn’t click the check box, but choose it using the keyboard for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check whether or not a cookie is set with every page
After doing a bit of processing, I want to set a cookie value to
I want to get the session cookie of a website. Unfortunately the Set-Cookie-Header doesn't
I want to set a cookie whenever a user visits a page, so not
I want to remove a cookie I set. If I do this by giving
I want to set a binding. The problem is that the target is of
I want to set a cookie with the country name and city location but
i want to set the cookie before the login lik:if the user fails to
I would like to set a cookie when a user submits a form. I
Is there any way I can set Cookie expiration date from other page -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.