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 6733917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:49:38+00:00 2026-05-26T10:49:38+00:00

This is borrowed from another question I made on the site, but would have

  • 0

This is borrowed from another question I made on the site, but would have got really messy.

So using some of the code from one of the repliers, how do I get this code to work… or have I got it completely wrong.

Select Options are:

<select style="width: 220px; display: none;" id="speedB" name="category">
    <option value=""<?if ($category == ""){?> selected="selected"<?}?>>Please Select</option>
    <option value="1"<?if ($category == "1"){?> selected="selected"<?}?>>Pest Inspectors</option>
    <option value="3"<?if ($category == "3"){?> selected="selected"<?}?>>Building Inspectors</option>
    <option value="2"<?if ($category == "2"){?> selected="selected"<?}?>>Removalists</option>
    <option value="5"<?if ($category == "5"){?> selected="selected"<?}?>>Conveyancing</option>
    <option value="4"<?if ($category == "4"){?> selected="selected"<?}?>>Pool Inspectors</option>
</select>

JavaScript:

$('#speedB').change(function() {
                      var myTypes = {
                        '': '.nothing',
                        '1': '.pest',
                        '2': '.build',
                        '3': '.removals',
                        '4': '.legal',
                        '5': '.pool'
                      }
                      var selectedType = myTypes[$(this).val()];
                      $('#topright').html('<div class="'+selectedType+'"/></div>');
                    });

HTML:

<div id="topright"></div>

CSS:

#topright {
height: 70px;
position: absolute;
right: 0;
top: 0;
width: 70px;
}
.pest {
background: url("images/pestcorner.png") no-repeat scroll 0 0 transparent;
}
.build {
background: url("images/buildcorner.png") no-repeat scroll 0 0 transparent;
}
.removals {
background: url("images/removalscorner.png") no-repeat scroll 0 0 transparent;
}
.legal {
background: url("images/legalcorner.png") no-repeat scroll 0 0 transparent;
}
.pool {
background: url("images/poolcorner.png") no-repeat scroll 0 0 transparent;
}

Essentially, I want user to select from select box, and that invokes display of the css class.

I think I have screwed the js up.

  • 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-26T10:49:39+00:00Added an answer on May 26, 2026 at 10:49 am

    I ‘d do it like this:

    First, add HTML data attributes with the corresponding class name for each option:

    <select style="width: 220px; display: none;" id="speedB" name="category">
        <option data-class="nothing" value=""<?if ($category == ""){?> selected="selected"<?}?>>Please Select</option>
        <option data-class="pest" value="1"<?if ($category == "1"){?> selected="selected"<?}?>>Pest Inspectors</option>
        <option data-class="build" value="3"<?if ($category == "3"){?> selected="selected"<?}?>>Building Inspectors</option>
        <option data-class="removals" value="2"<?if ($category == "2"){?> selected="selected"<?}?>>Removalists</option>
        <option data-class="legal" value="5"<?if ($category == "5"){?> selected="selected"<?}?>>Conveyancing</option>
        <option data-class="pool" value="4"<?if ($category == "4"){?> selected="selected"<?}?>>Pool Inspectors</option>
    </select>
    

    This way the relationships between CSS class and selected option are nicely prominent.
    You can then do:

    $('#speedB').change(function() {
        $('#topright').html('<div class="'+$(this).find(":selected").data("class")+'"/></div>');
    });
    

    Apart from that, you got the solution yourself (extra “.” in the name of the class being added).

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

Sidebar

Related Questions

Take the code below, adapted from this question : //Borrowed from another question because
I have borrowed code from this link PHP regex templating - find all occurrences
#&q=car&category=Car%20Audio%2CAccessories&brand= I borrowed a this function from a previous question asked on SO: function
Title borrowed from this question , of which this one is not a duplicate.
The following gist: https://gist.github.com/1876791 (borrowed from the demo in this question ) is a
I have some code that I borrowed from a long while ago that sets
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw
This is my first post here and I wanted to get some input from
This following code example is borrowed from MSDN here . I am not getting

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.