How about something like this
$(document).ready(function(){ $("#showwhat").change(function() { show_output( $(this).val () ); }); function show_output(selected) { var output = ""; if(selected == "Tomorrow") output = "You Selected " + selected; $("#output").html(output); } }); On Apr 12, 6:49 pm, djn12313 <djn12...@gmail.com> wrote: > 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); > > };