catch selected index onchange event trigger

Posted on 2007-10-10
Last Modified: 2008-01-09
$event = "window.location='technical-queries.php?jobnumber=".$jobnumber."&id='+this.selectedIndex+';";
$html .= '<select name="categories" onclick="this.onchange();" onchange="'.$event.'">'."\n";

I cant get my id value using the above.  Please advise.
Question by:ellandrd
    LVL 75

    Accepted Solution

    if the ID is the 0 based number of the option then it should work
    If it is the value of the selection option you need
    LVL 75

    Expert Comment

    by:Michel Plungjan
    Too many quotes?

     Question:  $event = "window.location='technical-queries.php?jobnumber=".$jobnumber."&id='+this.selectedIndex;";
    LVL 75

    Assisted Solution

    by:Michel Plungjan
    However if you do the onClick, the user cannot change the dropdown
    LVL 75

    Assisted Solution

    by:Michel Plungjan
    See this:

     ev = "alert('technical-queries.php?jobnumber=3&id='+this.selectedIndex);";
     html = '<select name="categories" onclick="this.onchange();" onchange="'+ev+'">'+"\n";
     html += '<option value="">Please select'+"\n";
    html += '<option value="a">a'+"\n";
    html += '<option value="b">b'+"\n";
    html += '</select>'+"\n";

    I would remove the onClick
    LVL 16

    Author Comment

    Thanks Michel.

    My original snippet of code had to many quotes to begin with and i also removed the onClick.  It is working nice and smooth now.


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Preface In the first article: A Better Website Login System ( I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
    This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now