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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:37:31+00:00 2026-05-20T21:37:31+00:00

I have a select with 2 optgroups. Is there a way to call an

  • 0

I have a select with 2 optgroups. Is there a way to call an function only if an option from the first optgroup is selected and call another function if an option from the second optgroup is selected?

  • 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-20T21:37:31+00:00Added an answer on May 20, 2026 at 9:37 pm

    Sure.

    HTML:

    What is your preferred vacation spot?<br>
    <SELECT ID="my_select"> 
    
    <OPTGROUP LABEL="OptGroup One." id="one">        
    <OPTION LABEL="Florida">Florida</OPTION>         
    <OPTION LABEL="Hawaii">Hawaii</OPTION>         
    <OPTION LABEL="Jersey">Jersey Shore</OPTION>    
    </OPTGROUP> 
    
    <OPTGROUP LABEL="OptGroup Two" id="two">  
    <OPTION LABEL="Paris">Paris</OPTION>  
    <OPTION LABEL="London">London</OPTION> 
    <OPTION LABEL="Florence">Florence</OPTION>  
    </OPTGROUP>
    
    </SELECT>
    

    JS:

    $("#my_select").change(function(){
        var selected = $("option:selected", this);
        if(selected.parent()[0].id == "one"){
            //OptGroup 1, do something here..
        } else if(selected.parent()[0].id == "two"){
            //OptGroup 2, do something here
        }
    });
    

    Example here: http://jsfiddle.net/pyG2v/

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

Sidebar

Related Questions

I have html like this: <select name=sortProducts id=sortProduct multiple=multiple> <optgroup label=Availability> <option selected=selected value=option1>Low
I have this form select: <select name=select_date id=select_date> <optgroup label=Select Date> <option value=0 selected=selected>Custom
I have a form <html> <head> </head> <body> <form> <select id=groups> <optgroup label=GroupA> <option
Now i have a select box. <select multiple size=5 name=interest> <optgroup label=Sports> <option value=>Footaball</option>
I have the following select: <select name=end id=end> <optgroup label=Morning> <option value=12:00a>12:00 am</option> <option
I have dropdown very similar to this: <select id='someSelect'> <option value=0>---select one---</option> <optgroup label=Bikes>
Here is my html <select class=selecturl> <optgroup label=Fruit> <option value=/something/167/remote>Apple</option> <option selected= value=/something/168/remote>Oranges</option> <option
I have the following code - example on jsFiddle <select> <optgroup label=Group1> <option value=11>Option
i have select <select id=parentId name=parentId><option value=1>ФАСАДНАЯ ШТУКАТУРКА&lt;BR /&gt;&lt;B&gt;&amp;#0171;STUC-O-FLEX&amp;#0187;&lt;/B&gt;</option> <option value=2>ФОНТАНЫ И САДОВАЯ МЕБЕЛЬ&lt;BR
Let's say we have: SELECT * FROM Pictures JOIN Categories ON Categories.CategoryId = Pictures.CategoryId

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.