New to jQuery and trying to port a simple Select-Box-Value-Hides/Shows-
a-Text-Box script from JS to jQuery. I'm sure this must be something
simple, but it's driving me nuts.

Note:  The following function is just an example for testing.  If I
define & call the Function below without any parms (e.g. explicitly
set the "#showwhat option:selected" inside the function), it works
fine.  But I have 2 Select Boxes where I need this behavior and would
like (if only for the sake of principle) to be able to pass in the
Selector and Value.

When passing in the Selector as a variable, the following snippet
executes only when the document loads, but not when the Selection
changes.  As mentioned if I explicitly set the "#showwhat
option:selected" inside the function the script executes the alert
each time the Select Box value changes.

Can anyone identify why this isn't working with the variable?  Maybe a
syntax problem forming the string with the variable?

-----------  sample ------------

$(document).ready(function(){
    $("#showwhat").change(onSelectChange("#showwhat"));
 });

function onSelectChange(test){
    var selected = $(test + " option:selected");
    var output = "";
    alert(selected.text());
    if(selected.text() == "Tomorrow"){
        output = "You Selected " + selected.text();
    }
    $("#output").html(output);
};

Reply via email to