Reputation: 39
I have a drop-down select menu which I'll want to use to return the value of a variable without a submit button and no page reloads. Index.html
<form action="fetch" method="get">
<p>
<select name="POS">
<option>SELECT COURSE</option>
<option value="POS">Agricultural Economics and Extension</option>
<option value="A">Another</option>
</select>
</p>
<p>
<input type="submit" name="check" id="check" value="Submit">
</p>
</form>
PHP Page
if(isset($_GET['check'])){
$POS = 'Agricultural Economics and Extension';
$CC = 'English, Mathematics, Chemistry';
$CO = 'Either Biology or Agricultural Science';
$OS = 'Any one of Physics, Geography and Economics';
}
Let the value of the drop down example
<option value="POS">Agricultural Economics and Extension</option>
Return the defined value in PHP without reloading the page.
$POS = 'Agricultural Economics and Extension';
Upvotes: 2
Views: 1308
Reputation: 1398
It looks like you are using jquery so you can just use the jquery get function to do this.
<select name="POS" onChange="getUpdate(this)">
<option>SELECT COURSE</option>
<option value="POS">Agricultural Economics and Extension</option>
<option value="A">Another</option>
</select>
<Script language="Javascript">
function getUpdate(selectObject) {
var value = selectObject.value;
$.get( "urlToyourPHPResults.php?POS="+value, function( data ) {
// Do something with returned data
});
}
</script>
Upvotes: 1