• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1259
  • Last Modified:

How to submit form when jquery select is changed?

Experts,

I need help with my jQuery syntax.

How can I submit my form when my jquery UI select is changed?

<script>
$(function(){
	//DEFINE A SELECT MENU CLASS
	$(".select").selectmenu();
});
$(document).ready(function(){
	//AUTOMATICHALLY SUBMIT THE STOPPAGE DATE FORM IF DATE IS CHANGED
	$("#stoppage_date").change(function(){
		document.getElementById("stoppage_date_form").submit();
	});
});
</script>

Open in new window


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="stoppage_date_form">
<select name="stoppage_date" id="stoppage_date" class="select">
    <option value="">Stoppage Date</option>
    <?php 
    if(!empty($_SESSION['stoppage_date'])){
        echo'<option value="'.$_SESSION['stoppage_date'].'">'.$_SESSION['stoppage_date'].'</option>';
    }
    ?>
    <option value="<?php echo date('m-d-Y'); ?>"><?php echo date('m-d-Y'); ?></option>
</select>
</form>

Open in new window

0
evibesmusic
Asked:
evibesmusic
  • 3
  • 3
1 Solution
 
GaryCommented:
$("#stoppage_date").change(function(){ $("#stoppage_date_form").submit() })

Open in new window

0
 
evibesmusicAuthor Commented:
@Gary:

Sorry but, the following is still not working for me:

$(function(){
      //DEFINE A BUTTON CLASS
      $(".button").button();
      //DEFINE A SELECT MENU CLASS
      $(".select").selectmenu();
});
$(document).ready(function(){
      //AUTOMATICHALLY SUBMIT THE STOPPAGE DATE FORM IF DATE IS CHANGED
      $("#stoppage_date").change(function(){
            $("#stoppage_date_form").submit()
      })
});
0
 
GaryCommented:
Can you post the rendered HTML of the page
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
evibesmusicAuthor Commented:
Rendered code:
<!DOCTYPE HTML>
<html><!-- InstanceBegin template="/Templates/work_stoppage_template.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<!-- InstanceEndEditable -->
<!-- BEGIN STYLE SHEETS -->
<link rel="stylesheet" type="text/css" href="css/styles.css"/>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/themes/sunny/jquery-ui.css" />
<!-- END STYLE SHEETS -->
<!-- BEGIN SCRIPTS -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script>
<!-- BUTTON CLASS -->
<script>
$(function(){
	//DEFINE A BUTTON CLASS
	$(".button").button();
	//DEFINE A SELECT MENU CLASS
	$(".select").selectmenu();
});
$(document).ready(function(){
	//AUTOMATICHALLY SUBMIT THE STOPPAGE DATE FORM IF DATE IS CHANGED
	$("#stoppage_date").change(function(){ 
		$("#stoppage_date_form").submit()
	})
});
</script>
<!-- END BUTTON CLASS -->
<!-- LOG-IN SCRIPT -->
<!-- END LOG-IN SCRIPT -->
<!-- END SCRIPTS -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
    <!-- Begin Naviagtion -->
    <div id="navigation">
					<a href="./index.php" class="button">My Employees</a>
            <a href="./command_center.php" class="button">Command Center</a>
            <a href="./reports.php" class="button">Reports</a>
			<div style="float:right;">
                <form action="/work_stoppage/index.php" method="post" id="stoppage_date_form">
                    <select name="stoppage_date" id="stoppage_date" class="select">
                        <option value="">Stoppage Date</option>
                        <option value="08-10-2014">08-10-2014</option>                        <option value="08-09-2014">08-09-2014</option>
                        <option value="08-10-2014">08-10-2014</option>
                    </select>
                </form>
			</div>
        	</div>
    <!-- End Naviagtion -->
</body>
<!-- InstanceEnd --></html>

Open in new window

0
 
GaryCommented:
Remove the earlier code and change your plugin code to this

$(".select").selectmenu({
	change: function() {
		$("#stoppage_date_form").submit();
	}
});

Open in new window

0
 
evibesmusicAuthor Commented:
@Gary

Bingo! 500 Duffs...I mean...points to you!

Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now