I have a page at the following URL: http://www.streetkids.org/ways_to_donate/make_donation2.php which is a basic donation page. The two page sections you see on the page "One Time Gift" or "Monthly Subscription" are normally hidden via a document.write via a body onload. Generally, all of this functions well. But, I want to expand the use a bit here so I want to pass a $_POST value to this page from another page which hides or shows these two sections based on this passed value. So, if the value in "once", I want the div with the id="onetime" to be visible and the other div to be hidden. If the value is "monthly", then the opposite would happen. I have tried to use a combination of PHP and javascript in the following way:
I have a script in the head:
function showhidefield($button) {
switch($button) {
case 'once':
//alert("One Time");
document.getElementById('once').style.display = "block";
document.getElementById('subscription').style.display = "none";
break;
case 'monthly':
//alert("monthly");
document.getElementById('once').style.display = "none";
document.getElementById('subscription').style.display = "block";
break;
case 'matchaid':
if(document.getElementById('reclaimTax').checked != true) {
document.getElementById('matchaid').style.display ='none';
} else {
document.getElementById('matchaid').style.display = 'block';
}
/*document.getElementById('matchaid').style.display = "block";*/
break;
case 'other-one-time':
if(document.getElementById('one_time_set').value == "other") {
document.getElementById('otherOneTime').style.display = 'block';
} else {
document.getElementById('otherOneTime').style.display = 'none';
}
break;
default:
//alert("default");
document.getElementById('once').style.display = "block";
document.getElementById('subscription').style.display = "none";
document.getElementById('matchaid').style.display = "none";
}
}
I have tried variations on the following code to show/hide the divs based on the $_POST value:
<?php if($_POST['freq'] == "once") { ?>
<script type="text/javascript" language="JavaScript">
showhidefield('once');
</script>
<?php
} elseif($_POST['freq'] == "monthly") { ?>
<script type="text/javascript" language="JavaScript">
showhidefield('monthly');
</script> <?php
}
?>
I have also tried to keep the js totaly inside of php by using:
echo "<script type='text/javascript' language='JavaScript'>
showhidefield('once');
</script>"
Now this is supposed to all happen as the page loads because we are just arrivng here from the sending page.
All help is appreciated.
Dave