Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Passing a parameter to a function in JQuery

Posted on 2009-02-12
Medium Priority
Last Modified: 2012-06-27
I have the following code. This is a function for a select-menu, which has several options (id: select1, select2, etc). I could copy the function for each select option, but I prefer to pass a parameter to it. I'm not really familiar with JQuery, so I wonder how to do this.
		$("#select1").change( function(){
		var selected = $("#select1 option:selected");		
		if(selected.val() == 0){ $("#warning").show(); }
		else { $("#warning").hide(); }

Open in new window

Question by:R7AF
LVL 11

Accepted Solution

JohnSixkiller earned 1000 total points
ID: 23622079
                $("select").change( function(){ // this will select all SELECTs on page                
                if(this.value == 0){ $("#warning").show(); } // compare actual object's selected value 
                else { $("#warning").hide(); }

Open in new window

LVL 13

Author Closing Comment

ID: 31546019
Thank you!

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

564 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