Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help to show a hide field that is not empty after the page reload

    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.
    Code:
    /*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>
    Code:
    /*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";
    				}
    		}
    
    	}
    }

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry about that abduraooft.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •