Solved

jQuery

Posted on 2015-02-23
5
42 Views
Last Modified: 2015-02-24
I have a jQuery on Change function.  I need to make it into a onChange or on Submit Function.  I need both,  How do I write that?
<script>
	$(document).ready(function () {
		 $('select').change(function () { 

Open in new window

0
Comment
Question by:rgranlund
  • 2
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 40626803
Hi,
you might try to create a dedicated function which can then be used when you bind it to the two events like
var customFunction = function() {
   ...
}
$('select').change(customFunction);
$('form').submit(customFunction);
...

Open in new window

HTH
Rainer
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40627019
That did not really work.
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 40627044
Hi,
I created a really small sample here
http://jsfiddle.net/EE_RainerJ/nvvu5mc8/

I prefer to use the "on" handler - but thats the only difference.
Could you perhaps add more info about your scripts?

HTH
Rainer
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40628156
just attach it to an onchange event handler, and within that code, do a form submit on whatever conditions warrant it:

$('select').change(function () {
       if ( this.val() == 4 )
             $(form).submit();
       else
              .....
}

Open in new window

0
 
LVL 7

Author Closing Comment

by:rgranlund
ID: 40628261
I wrote earlier that it did not work.  I looked everything over and I had a spelling error.  Sorry for making you post twice.  Thanks for your help!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult 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 code hide show and toggles. 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…

831 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