Hi Bob,
I tried something different to show the error message using javascript to hide and show the form. I also create a hidden textbox for the cost of the project from db table and another textbox for the total of the donation based on project selection to use it in JS code.
window.addEvent('domready', function() {
ShowForm();
});
function ShowForm(){
var a = document.getElementById('project_cost').value;
var b = document.getElementById('hidden_sum').value;
if (b > a){
alert("Thank you for your donation but this project is now fully funded and work will be starting soon. Please click the arrow back button in your browser to select another project to donate. Thank you for your support!");
document.getElementById('show_errormessage').style.display=""; // this is for showing
document.getElementById('show_ccform').style.display="none"; //hide
} else {
document.getElementById('show_ccform').style.display=""; // this is for showing
document.getElementById('show_errormessage').style.display="none";
}
}
Somehow the problem still exist. Why the two hidden textboxes cannot compare knowing that they are both decimal in the database. Below is my sql query for two different table with hidden textboxes as my output data.
Showing the SUM() based on donation amount per project name from a table
<?php
$project_name = JRequest::getString('project_name', '', 'get');
$project_cost = JRequest::getString('project_cost', '', 'get');
$hidden_sum = JRequest::getString('hidden_sum', '', 'post');
// Get user object -information from Joomla
$db =& JFactory::getDBO();
$query = "
SELECT SUM(`donate_amount_other`) as sum, `project_name`, `project_cost`
FROM `#__table`
WHERE `project_name` = '{$project_name}'
GROUP BY `project_name`
";
$db->setQuery($query);
$data = $db->loadObjectList();
foreach($data as $a) {
echo '<div class="formfield">Current Total Donation Amount for Project '.$a->project_name.' you selected is <b><u>$'.number_format($a->sum).'</u></b></div>';
echo '<input type="text" id="hidden_sum" name="hidden_sum" value="'.$a->sum.'" />';
}
Showing the other data table with the project cost
$db =& JFactory::getDBO();
$query = "
SELECT *
FROM `#__othertable`
WHERE `project_name` = '{$project_name}'
";
$db->setQuery($query);
$data = $db->loadObjectList();
if (empty($data)) {
echo "<p align='center'>Sorry, no project available for the school you selected</p>";
} else {
foreach($data as $d) {
echo '<div class="formfield "><label>Project Name: </label><input maxlength="150" size="60" class="" title="" type="text" value="'.$d->project_name.'" name="project_name" id="project_name" readonly/></div>';
echo '<div class="formfield "><label>District Name: </label><input maxlength="150" size="60" class="" title="" type="text" value="'.$d->district.'" name="district" id="district" readonly /></div>';
echo '<div class="formfield "><label>School Name: </label><input maxlength="150" size="60" class="" title="" type="text" value="'.$d->SchoolName.'" name="SchoolName" id="SchoolName" readonly /></div>';
echo '<div class="formfield "><label>Principal Name: </label><input maxlength="150" size="60" class="" title="" type="text" value="'.$d->principal_name.'" name="principal_name" id="principal_name" readonly /></div>';
echo '<div class="formfield "><label>Category Level: </label><input maxlength="150" size="60" class="" title="" type="text" value="'.$d->category_code.'" name="category_code" id="category_code" readonly /></div>';
echo '<div class="formfield "><label>Project Code: </label><input maxlength="150" size="60" class="" title="" type="text" value="'.$d->project_code.'" name="project_code" id="project_code" readonly /></div>';
echo '<div class="formfield "><label>Project Description: </label><textarea id="project_description" cols="33" rows="3" width="60px;" class="" name="project_description" readonly>'.$d->project_description.'</textarea></div>';
echo '<div class="formfield "><label>Project Type: </label><input maxlength="150" size="60" class="" title="" type="text" value="'.$d->project_type.'" name="project_type" id="project_type" readonly /></div>';
echo '<div class="formfield "><label>Project Status: </label><input maxlength="150" size="60" class="" title="" type="text" value="'.$d->project_status.'" name="project_status" id="project_status" readonly /></div>';
echo '<div class="formfield "><label>Project Cost: </label><input maxlength="150" size="60" class="" title="" type="text" value="'.$d->project_cost.'" name="project_cost" id="project_cost" readonly /></div>';
}
}
?>
then I have this two <div> to show/hide
<div id="show_errormessage">
<fieldset class="formsection" id="cc_doe" style="border:none !important">
<p>Thank you for your donation but this project is now fully funded and work will be starting soon. Please click the arrow back button in your browser to select another project to donate. Thank you for your support!</p>
</fieldset>
</div>
<div id="show_ccform">
<fieldset class="formsection" id="cc_doe" style="border:none !important">
<!-- <legend class="hide">Donate....Helping School and Building Communities</legend> -->
<div id="donate-credit_card">
<p><em style="font-size:12px">Note: Please review the project you selected and enter your donation information below. </em></p>
......some form here......
</fieldset>
</div>
Do you have other solution to make this work? I am guessing that the two hidden textboxes although are both decimal in the database, can't compare together. Any suggestion please? Thanks and hope to hear from you soon.