excuse my poor titling skills. I wish to run a simple javascript function that for now only returns an echo from a php page. I have linked to the function and it gets to the function but fails to complete. I don't think i have anything noticeably wrong with the code but nothing happens.
Javascript function:
<script type="text/javascript">
function PopulateBoxes(){
$.post('PopulateBoxes.php', {date: SelectTourForm.lst_MonthDrop.value },
function(output){
$('#txt_Duration').hmtl(output).show();
}
);
}
</script>
PopulateBoxes.php:
<?php
echo "This is a test";
?>
The drop down menu:
<form id="SelectTourForm" style="margin:5px;">
<table border="0" align="center" width="100%">
<tr>
<td>
<label style="color:#FFF; font:Georgia, 'Times New Roman', Times, serif; font-size:20px; margin-left:10px; margin-top:25px">Select Tours Details</label>
</td>
</tr>
<tr>
<td>
<select name="lst_MonthDrop" style="background-color:#FF9933; color:#FFF; border:none; margin-top:10px; margin-left:10px;" onchange="PopulateBoxes();">
<option>Please Select</option>
<?php
include 'populatedrodown.php';
foreach ( $results as $option ) :
?>
<option value="<?php echo $option->Date; ?>"><?php echo $option->Date; ?></option>
<?php endforeach; ?>
</select>
<input type="submit" name="btn_TourSearch" id="btn_TourSearch" value="Search" style="background:#009300; border-radius:5px; border-color:#009300; color:#FFF;margin-left:5px;" />
</td>
</tr>
<tr>
<td></td>
</tr>
</table>
<p> </p>
</form>
Thanks in advance.
Your error was at SelectTourForm.lst_MonthDrop.value, used as is, JavaScript does not recognized it.
I tested this for your reference and worked: As lst_MonthDrop only has name, having no id, we get its value by:
$("select[name=lst_MonthDrop]").val()
Here is the test structure:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
function PopulateBoxes(){
$.post('PopulateBoxes.php',
{date: $("select[name=lst_MonthDrop]").val()},
function(output){
$('#txt_Duration').html(output).show();
});
}
$(document).ready(function () {
// just for test
PopulateBoxes();
});
</script>
</head>
<body>
<div id="txt_Duration"></div>
<?php
// your form here...
?>
</body>
</html>
I got this screenshot:
problems:
1: hmtl
should be html
2: SelectTourForm.lst_MonthDrop.value
should be $("select[name=lst_MonthDrop]").val()
3: There is no element with id txt_Duration
in your shown html. Create it.
4: populatedrodown.php
is likely to be misspelled. Missing a letter p
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.