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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:38:52+00:00 2026-06-18T09:38:52+00:00

I have a page that gets values from a DB, I can’t control the

  • 0

I have a page that gets values from a DB, I can’t control the values / how they are called, but the end result looks like standard HTML code, for example:

<div id="myDiv" class="controls">
    <select id="jform_province" name="jform[province]">
        <option value="AB">Alberta</option>
        <option value="BC">British Columbia</option>
        <option value="MB">Manitoba</option>
    </select>
</div>

I’m looking to put a script at the end of the page that can modify the option elements by say adding a function so it looks like this:

<option value="AB" onClick="someFunction()">Alberta</option>

How can I modify the code? I know how to edit the entire content of the div but I want to change the elements, I will not know what the values of the elements are so the script needs to find all option tags in “myDiv” (I have other lists on the page I don’t want changed) and add that code to all of them.

Thanks

  • 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-18T09:38:53+00:00Added an answer on June 18, 2026 at 9:38 am

    Just attach an event handler:

    document.getElementById('jform_province').onchange = function() {
      switch(this.options[this.selectedIndex].value) {
        case "AB": someFunction(); break;
        // define other cases as needed
      }
    };
    

    Note that <option> elements do not fire onclick events when selected, and even if they did it wouldn’t detect alternate input methods such as using the keyboard. The code above provides an alternative.

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

Sidebar

Related Questions

I have created a page called profile.php that gets a value from mainpage.php, by
I have this function in jQuery that gets data from a page with POST,
So I have a php page that gets data from database and displays a
I have a dynamic page that gets a certain number of results for rooms
I have a datalist inside a usercontrol that gets loaded into a page where
I have a page that uses the Telerik RadListView control and a Telerik RadDataPager
I have a dropdown css menu that gets gets hidden behind the main page
I have an ASP.NET dropdownlist called #ddlDateRange that contains several items. Possible values in
I have a working script that passes a value from a popup page to
I have a page called connect.php This page connects with twitter and gets the

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.