Solved

jQuery

Posted on 2015-02-23
5
40 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 32

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

What Security Threats Are You Missing?

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)

705 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

17 Experts available now in Live!

Get 1:1 Help Now