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

  • Home
  • SEARCH
  • 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 5981939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:00:55+00:00 2026-05-22T22:00:55+00:00

I currently have 3 combo boxes containing values which apply styles to the page

  • 0

I currently have 3 combo boxes containing values which apply styles to the page using javascript.

All these styles are applied to a cookie and read on body load, however I’d like to also set the combo box’s values to match the applied styles.

How do I go about setting a combo box value based on a cookie or applied style?

<select name="sizes" onchange="fontSize(accessibility.sizes.value);"> 
  <option value='-1'>Select</option>
  <option value='10'>Small</option> <option value='12.75'>Medium</option>
  <option value='15.5'>Large</option>
</select>
function fontSize(textSize) { 
  var element = document.getElementById('content'); 
  if (element) {
   element.style.fontSize = textSize + 'px'; 
   createCookie("Font Size", textSize, 365);   
  }
} 

Thanks in advance!

  • 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-05-22T22:00:56+00:00Added an answer on May 22, 2026 at 10:00 pm

    If changing the select is changing the style, first select the relevant value then trigger the onchange. Notice I changed your script to save the selectedIndex and to apply the change after I set the index. Also please notice I pass (this) which the the select object itself and I have added an ID to it. Lastly I put the medium fontsize as the first item in case people want to reset. Please change that to whatever is the default font size

    window.onload=function() {
      var sel = document.getElementById('sizes');// get the select with ID=sizes
     // the following statement gets the select and sets the index to the cookie content if
     // there IS a cookie, else it sets it to 0
     var idx = getCookie("FontSizeIdx") || 0;
      sel.selectedIndex = parseInt(idx,10); // make sure it is a number
     // now call the function and pass the select to it
      fontSize(sel);
    }
    function fontSize(sel) { // select object is passed as (this) and ends up here as (sel)
      var textSize = sel.options[sel.selectedIndex].value; // get the value
      var element = document.getElementById('content'); // get the content object
      if(element) { // does it exist?
        element.style.fontSize = textSize + 'px'; // set the font size 
        createCookie("FontSizeIdx", sel.selectedIndex, 365); // save the index
      }
    } 
    
    <select name="sizes" id="sizes" onchange="fontSize(this);"> 
    <option value='12.75'>Select (default is medium)</option> 
    <option value='10'>Small</option> 
    <option value='12.75'>Medium</option> 
    <option value='15.5'>Large</option> 
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have an existing database and I am using the LINQtoSQL generator tool
I currently have a functioning in-house Windows Forms application which extensively uses the DataGridView
I have multiple combo and option boxes whose visibility is set true or false
I have an Access 2003 project in which all data is stored in SQL
I have cascading data-bound combo boxes, however, if the second of the two boxes
Currently we have a makeshift combobox which is comprised of a textbox, an arrow
I am using GWT with GWT-EXT running in glassfish. I create 2 combo boxes
I currently have a Combo box that has data that is bind from a
I have a function called bodyStyle() which accepts 5 values: bodyStyle(textCol, backCol, heading1Col, headingsCol,
I'm currently working on an app using MVVM that needs to have some data

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.