Hi,
OK I have done one part correctly ,
Now, the problem is when i click on the calculate button it does not work , some problem with the onClick attribute of the button ,
Kindly Help me with this ,
Ok I will Post the code here
////The page duedate.php
Code: Select all
<?php
require_once( './config.php' );
function safe_get_string($param, $default) {
if (array_key_exists($param, $_GET)) {
if (!get_magic_quotes_gpc()) {
return addslashes($_GET[$param]);
}
else {
return $_GET[$param];
}
}
else {
return $default;
}
}
function safe_get_integer($param, $default) {
if (array_key_exists($param, $_GET)) {
return (int) $_GET[$param];
}
else {
return $default;
}
}
$action = safe_get_string( 'action', '' );
ob_start();
if ( $action == '' ) {
?>
<table width="483" height="286" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3"><img style="vertical-align: bottom;" src="<?php echo $main_path; ?>images/duedatenew.gif" width="483" height="34" alt=""></td>
</tr>
<tr>
<td rowspan="2" valign="TOP"><img src="<?php echo $main_path; ?>images/main_02.jpg" width="11" height="252" alt=""></td>
<td valign="TOP">
<div style="padding: 12px; font-family: arial; font-size: 10pt; color: #333333;">
<span style="color: #669900; font-size: 14pt; font-weight: bold; font-family: times;"> Due Date Calculator</span>
<p style="margin-bottom: 0px; margin-top: 8px;">
Not sure when your baby is due? Our handy calculator will help predict your most likely due date.
</p>
<p style="margin-bottom: 0px; margin-top: 8px;">
<strong>What was the date of first day of your last period?</strong>
<br />
<input type="TEXT" size="12" id="lastperiod" name="lastperiod">
<input type="button" onclick="displayDatePicker('lastperiod');" value="select"/>
</p>
<p style="margin-bottom: 0px; margin-top: 8px;">
<strong>Adjusted cycle length:</strong> If you know that your cycle is shorter or longer than 28 days, please adjust the number below.
<br />
<select id="cyclelength">
<option value="21">21 days</option>
<option value="22">22 days</option>
<option value="23">23 days</option>
<option value="24">24 days</option>
<option value="25">25 days</option>
<option value="26">26 days</option>
<option value="27">27 days</option>
<option value="28" SELECTED>28 days</option>
<option value="29">29 days</option>
<option value="30">30 days</option>
<option value="31">31 days</option>
<option value="32">32 days</option>
<option value="33">33 days</option>
<option value="34">34 days</option>
<option value="35">35 days</option>
<option value="36">36 days</option>
<option value="37">37 days</option>
</select>
</p>
<p align="RIGHT" style="margin-bottom: 0px; margin-top: 8px;">
[b] <input type="button" onclick="ajaxFunction('action=calculate&lastperiod='+document.getElementById('lastperiod').value+'&cyclelength='+document.getElementById('cyclelength').value);">Calculate my due date</button>[/b]
</p>
</div>
</td>
<td rowspan="2" valign="TOP"><img src="<?php echo $main_path; ?>images/main_04.jpg" width="10" height="252" alt=""></td>
</tr>
<tr>
<td><img src="<?php echo $main_path; ?>images/main_05.jpg" width="462" height="12" alt=""></td>
</tr>
</table>
<?php
}
elseif ( $action == 'calculate' ) {
$lastperiod2 = safe_get_string( 'lastperiod', date( 'd/m/Y' ) );
$lastperiodexpl = explode('/',$lastperiod2);
$lastperiod = $lastperiodexpl[1] . "/" . $lastperiodexpl[0] . "/" . $lastperiodexpl[2];
$cyclelength = safe_get_integer( 'cyclelength', 28 );
$from_date_raw = @strtotime( $lastperiod );
$from_date = getdate( $from_date_raw );
$this_date_raw = time();
$this_date = getdate( $this_date_raw );
$from_year = $from_date['year'];
$this_year = $this_date['year'];
$days = date( 'z', $this_date_raw );
while ( $from_year < $this_year ) {
$days = $days + 365 + date( 'L', mktime( 0, 0, 0, 12, 31, $from_year ) );
$from_year++;
}
$days -= date( 'z', $from_date_raw );
$weeks = -1;
$days_remaining = -1;
if ( $days >= 0 ) {
$weeks = floor( $days/7 );
$est_date_raw = mktime( 0, 0, 0, $from_date['mon'], $from_date['mday'] + 280, $from_date['year'] );
$est_date = getdate( $est_date_raw );
$days_remaining = 280 - $days;
if ( $days_remaining >= 0 ) {
$weeks_remaining = floor( $days_remaining/7 );
$days_remaining_2 = $days_remaining % 7;
}
}
if ( $days >= 0 ) {
if ( $weeks < 42 ) {
if ( ( $weeks % 10 ) != 1 ) {
$firstline = "You are $weeks weeks pregnant.";
}
else {
$firstline = "You are $weeks week pregnant.";
}
if ( $days_remaining > 0 ) {
$firstline .= " You are due on " . date( 'd/m/y', $est_date_raw ) . '.';
}
}
else {
$firstline = "You are not pregnant or already gave birth.";
}
}
else {
$firstline = "You are not pregnant. Not yet.";
}
$secondline = '';
if ( $days_remaining > 0 ) {
$secondline = 'You have';
if ( $weeks_remaining > 0 ) {
if ( ( $weeks_remaining % 10 ) != 1 ) {
$secondline .= " $weeks_remaining weeks";
}
else {
$secondline .= " $weeks_remaining week";
}
}
else {
$secondline .= " only";
}
if ( $days_remaining_2 > 0 ) {
if ( ( $days_remaining_2 % 10 ) != 1 ) {
$secondline .= " $days_remaining_2 days";
}
else {
$secondline .= " $days_remaining_2 day";
}
}
$secondline .= " left.";
}
$show_text = false;
if ( ( $weeks >= 0 ) && ( $weeks <= 41 ) ) {
$show_text = true;
}
?>
<table width="483" height="286" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3"><img style="vertical-align: bottom;" src="<?php echo $main_path; ?>images/main_01.jpg" width="483" height="34" alt=""></td>
</tr>
<tr>
<td rowspan="2" valign="TOP"><img src="<?php echo $main_path; ?>images/main_02.jpg" width="11" height="252" alt=""></td>
<td valign="TOP" height="240">
<div style="padding: 12px; font-family: times; font-size: 12pt; color: #669900;">
<span style="color: #669900; font-size: 14pt; font-weight: bold; font-family: times;"> Your Calculated Due Date</span>
<p style="margin-bottom: 0px; margin-top: 8px;">
<?php echo $firstline; ?>
</p>
<?php
if ( $secondline != '' ) {
?>
<p style="margin-bottom: 0px; margin-top: 8px;">
<?php echo $secondline; ?>
</p>
<?php
}
if ( $show_text ) {
?>
<p style="margin-bottom: 0px; margin-top: 8px;">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="TOP"><img src="<?php echo $main_path; ?>images/weeks/<?php echo $__weeks_pictures[$weeks]; ?>"></td>
<td> </td>
<td valign="TOP">
<span style="color: #333333; font-size: 14pt; font-weight: bold; font-family: times;">Week <?php echo ( $weeks + 1 ); /* if ( ( $weeks + 1 ) % 10 == 1 ) { echo 'st'; } elseif ( ( $weeks + 1 ) % 10 == 2 ) { echo 'nd'; } elseif ( ( $weeks + 1 ) % 10 == 3 ) { echo 'rd'; } else { echo 'th'; }*/ ?></span>
<br />
<span style="color: #333333; font-size: 8pt; font-family: arial;"><?php echo $__weeks_data[$weeks]; ?></span>
</td>
</tr>
</table>
</p>
<?php
}
?>
</div>
</td>
<td rowspan="2" valign="TOP"><img src="<?php echo $main_path; ?>images/main_04.jpg" width="10" height="252" alt=""></td>
</tr>
<tr>
<td valign="TOP"><img src="<?php echo $main_path; ?>images/main_05.jpg" width="462" height="12" alt=""></td>
</tr>
</table>
<?php
}
$content = ob_get_contents();
ob_end_clean();
$content = str_replace( array( "\r\n", "\n" ), "", $content );
$content = str_replace( "'", "'+\"'\"+'", $content ); //"
echo "document.getElementById('duedatecontainer').innerHTML='$content';";
?>
//duedate.js file with the AjaxFunction
var main_path = "
http://www.bumples.co.uk/duedate/";
function ajaxFunction(req)
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
if ( xmlHttp.responseText != '' ) {
eval( xmlHttp.responseText );
}
}
}
xmlHttp.open("GET",main_path+"duedate.php?"+req,true);
xmlHttp.send(null);
}