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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:51:24+00:00 2026-06-12T14:51:24+00:00

i am having a very frustrating problem. I have this code which filters out

  • 0

i am having a very frustrating problem. I have this code
which filters out my results and inputs them into a select box

var syn = <?=json_encode($syn)?>;
function filterByCity() {
        var e = document.getElementById("city_filter");
        var city = e.options[e.selectedIndex].value;
        var selectOptions = document.getElementById('syn_list');
        selectOptions.options.length = 0;

        for (i = 0; i < syn.length; i++) {
            if (city == syn[i]['city'] || city == 'all') {
                selectOptions.options[selectOptions.options.length] = new Option(syn[i]['name'], syn[i]['id'] + '" onclick="updateTxtContent(\'' + syn[i]['id'] + '\')');
            }
        }
    }

as you might see i am adding a onclick listener to every select “option” which look great in the source code of the page itself but if i copy it into an edit i notice this
my problem is that the “updateTxtContent()” function is not called.

<select size="10" name="syn_list" id="syn_list" class="span12" dir="rtl" style="text-align:right;">
<option value="13&quot; onclick=&quot;updateTxtContent('13')">option a</option>
<option value="14&quot; onclick=&quot;updateTxtContent('14')">option b</option>

obviously there should be a better way to do this that i am not aware of.

  • 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-12T14:51:25+00:00Added an answer on June 12, 2026 at 2:51 pm

    I think you want to have your event handler on your select rather than on the option. See this fiddle for what I mean

    <select size="10" name="syn_list" id="syn_list" class="span12" dir="rtl" style="text-align:right;" onchange="updateTxtContent();">
    <option value="13">option a</option>
    <option value="14">option b</option>
    </select>
    
    <script>
    function updateTxtContent(){
     alert($("#syn_list").val());   
    }   
    </script>
    ​
    

    Or since it looks like you aren’t using jQuery:

    function updateTxtContent(){
        var e = document.getElementById("syn_list");
        var f = e.options[e.selectedIndex].value;    
        alert(f);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a very frustrating time solving this issue. I have a model which automatically
I am having a very frustrating problem with Microsoft Visual Web Developer. I have
I'm having a very frustrating problem with my javascript files. I have one global
Im having a very strange problem, i have a complicated view that returns incorrect
I am having a frustrating problem with virtual directory mapping in my very simple
I'm having a very frustrating problem with PopupWindow on Android. I've implemented my own
I seem to be having a very frustrating time with an inherited class calling
I having a very weird problem for my asp project. My project can run
Im having a very odd problem. Im trying to install a Python program. Im
I'm having a very simple problem. I'm new to WordPress and I'm trying to

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.