jQuery Function that fires when a select value has been changed?
Good day guys. So I'm trying to work on this simple jQuery program that
triggers a function whenever and only whenever a select value has been
changed. I plan to use this simple function in a more complex program once
I make it work.
This is the code (it came from jQuery API website, and I modified it
slightly to try what I wanted to happen):
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>change demo</title>
<style>
div {
color: red;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<select id="selector" name="sweets">
<option>Chocolate</option>
<option selected="selected">Candy</option>
<option>Taffy</option>
<option selected="selected">Caramel</option>
<option>Fudge</option>
<option>Cookie</option>
</select>
<div></div>
<script>
$( "#selector" )
.on('change',(function () {
$( "select option:selected" ).each(function() {
<?php header("Location:jcue.php")?>
});
})
.change();
</script>
</body>
</html>
What I want to happen is that, the page should only redirect to jque.php
once the select input value has been changed. But what's happening in the
program is that it automatically redirects to another page without even
loading the current page itself. What's the problem? jQuery and Javascript
are the unexplored foreign lands for me in web programming, and I know
this is pretty basic to many web programmers, but I just need it (and I
really have to start learning Javascript, AJAX, and jQuery when I get to
have free time haha).
The complex program I'm going to use it to is a search results filtering
program. But before I can do that, I have to make this simple program
work.
Can anybody help me? Thank you. Answers will be greatly appreciated.
No comments:
Post a Comment