I need to call a javascript function from php through embedded html.
This is my function.
<script>
// THIS JAVASCRIPT REDIRECTS TO EDITUSER.PHP AND PASSES USERID VALUE.
function startMaint(mo, yr){
window.location = "startmaintenance.php?mo=" + mo + "yr=" + yr;
}
</script>
this is where i call my function.
<form method="POST" action="home.php">
<select name="monthselect">
<option value="" disabled selected> Select Month: </option>
<?PHP
echo"<option value=01>January</option>";
echo"<option value=02>February</option>";
echo"<option value=03>March</option>";
echo"<option value=04>April</option>";
echo"<option value=05>May</option>";
echo"<option value=06>June</option>";
echo"<option value=07>July</option>";
echo"<option value=08>August</option>";
echo"<option value=09>September</option>";
echo"<option value=10>October</option>";
echo"<option value=11>November</option>";
echo"<option value=12>December</option>";
?>
</select>
<select name="yearselect">
<option value="" disabled selected> Select Year: </option>
<?PHP
$year = 1920;
While($year <= date("Y")){
echo"<option value=$year>".$year."</option>";
$year++;
}
echo"</select>";
echo "</div>";
echo "<div class='center'>";
$strMonth = $_POST['monthselect'];
$strYear = $_POST['yearselect'];
echo "<input type='button' class='btn' name='start' value='Start' onclick='javascript:startMaint('".$strMonth."','".$strYear."');'>";
?>
</form>
The issue that I am having is that my code is not executing when i press the 'Start' button.
I am not sure if the syntax that I am using is correct when i pass the arguments to the function. any help would be appreciated.
if i manually input the values like this:
echo "<input type='button' class='btn' name='start' value='Start' onclick='javascript:startMaint(". 1 .",". 1980 .");'>";
It works fine. but if i replace the values with variables, the code does not execute...what i want to do is pass the $strMonth and $strYear values to the function.