...

View Full Version : Help to show a hide field that is not empty after the page reload



jmarian1
12-14-2009, 06:58 AM
Hi. I have a form and in the form is a checkbox use as a switch to hide and unhide a two textbox. When the other textbox is hide, the other is unhide such as the code below. When the user click the submit button on the first time and there is an error, it reloads and the id="fieldset.-in_honor" hide because it is set to hide initially but not empty. My problem is, I want to show the fieldset whichever is not empty after submit button is click and there is an error so user will not enter any more information to the other field. Is that possible? Please help. I have a hard time explaining it but hopefully you will get the idea. Thanks in advance and hope to hear from you as soon as possible.


/*toggle switch*/
<p><input type="checkbox" name="in_honor" value="" id="checkmemoriam" onclick="showHide(this.name);" />Please check to make this donation in honor of someone special.</p>

/*hide textbox but unhide when the switch is on or the checbox is check*/


<fieldset id="fieldset-in_honor" class="fieldgroup" style="display:none">
<legend class="hide">In Honor Of</legend>
<p>To make this donation in honor of someone special, please complete the two fields below:</p>
<div class="formfield" <?php echo highlight('donate_honor_name'); ?>>
<label for="donate_honor_name">Name:</label>
<input id="donate_honor_name" name="donate_honor_name" class="text" type="text" value="<?php safeEcho($form['donate_honor_name'])?>" />
<?php helper_error('donate_honor_name'); ?>
</div>
<div class="formfield" <?php echo highlight('donate_honor_acknowledgement'); ?>>
<label for="donate_honor_acknowledgement">Acknowledgement should be sent to:</label>
<textarea id="donate_honor_acknowledgement" name="donate_honor_acknowledgement"><?php safeEcho($form['donate_honor_acknowledgement'])?></textarea>
<?php helper_error('donate_honor_acknowledgement'); ?>
</div>

/*always show on first load of the page but once the checkbox is check, will need to hide and delete info entered*/

<fieldset id="fieldset-in_registration">
<label for="impact" style="font-weight:bold">B. Impact Areas</label>
<table>
<tr>
<td style="width:380px;text-align:left"><label for="d" id="deslist4" name="deslist4">Crime and Drug Use <a href="javascript:alert('Ensuring prevention and treatment programs and appropriate support services are available to people who are at risk for drug addiction and supporting efforts to reduce crime.');">what is this?</a></label></td>

<td style="float:right"> $<input id="d" name="d" class="text" type="text" value="<?php safeEcho($form['d'])?>" style="width:90px;" onChange="CalculateTotal()" />
<?php helper_error('d');?> </td>
</tr>
<tr>
<td style="width:380px;text-align:left"><label for="e" id="deslist5" name="deslist5">Early Childhood Development <a href="javascript:alert('Children are healthy, loved, nurtured, safe and have access to quality childcare and early education. This includes programs that increase parenting skills, providing books to all children and providing developmental screening for 3 and 4 year olds.');">what is this?</a></label></td>

<td style="float:right"> $<input id="e" name="e" class="text" type="text" value="<?php safeEcho($form['e'])?>" style="width:90px;" onChange="CalculateTotal()" />
<?php helper_error('e');?> </td>
</tr></table>



/*JAVASCRIPT FUNCTION*/
function showHide()
{
if (document.getElementById('checkmemoriam').checked)
{
if (document.getElementById('TotalC').value == "0.00")
{
document.getElementById('fieldset-in_honor').style.display=""; // this is for showing
document.getElementById('fieldset-in_registration').style.display="none";
}
else
{
var answer = confirm("You entered a total gift designation of $" + document.getElementById('TotalC').value + ". At this time, gifts made \"in honor of someone special\" are not eligible for the designation option. Clicking the OK button will delete all your designation(s). Do you want to continue?")
if (answer)
{
document.getElementById('TotalC').value="0.00";
document.getElementById('d').value="0";
document.getElementById('e').value="0";
document.getElementById('fieldset-in_honor').style.display=""; // this is for hiding
document.getElementById('fieldset-in_registration').style.display="none";

}
else
{
document.getElementById('checkmemoriam').checked=false;
}
}

}
else
{
if ((document.getElementById('donate_honor_name').value="") && (document.getElementById('donate_honor_acknowledgement').value=""))
{
document.getElementById('fieldset-in_honor').style.display="none"; // this is for hiding
document.getElementById('fieldset-in_registration').style.display="";
}
else
{
var answer = confirm("The field you are trying to close will delete all information you entered \"in honor of someone special\" but it will allow you to designate. Clicking the OK button will show the designation list. Do you still want to continue?")
if (answer)
{
document.getElementById('donate_honor_name').value = "";
document.getElementById('donate_honor_acknowledgement').value = "";
document.getElementById('fieldset-in_honor').style.display="none"; // this is for hiding
document.getElementById('fieldset-in_registration').style.display="";
}
else
{
document.getElementById('checkmemoriam').checked=false;
document.getElementById('fieldset-in_honor').style.display=""; // this is for showing
document.getElementById('fieldset-in_registration').style.display="none";
}
}

}
}

abduraooft
12-14-2009, 08:52 AM
Please follow http://www.codingforums.com/rules.htm
# 1.2) Do not crosspost- CodingForums.com is divided into various categories. When initiating a thread, always locate the most appropriate category, and post your question only ONCE, in that category. Do not post the same question in multiple categories.

jmarian1
12-14-2009, 10:24 PM
Sorry about that abduraooft.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum