Connecting Tech Pros Worldwide Forums | Help | Site Map

form problem

pradeepjain's Avatar
Needs Regular Fix
 
Join Date: Jul 2007
Location: India
Posts: 407
#1: Oct 12 '09
Hii guys,
I have a form where in on click of a checkbox i hide and show a textfield which is working fine . but when i refresh the page the text box gets hidden and the value is also lost ... is there any way so that when ever the checkbox is checked the textbox is visible along with its value. i have posted the code too.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="/JS/page.js"></script>
  2. <form name="test123" id="test2" method="POST">  
  3. <div class="fieldForm" id="fieldForm" >
  4. <fieldset id="personnel">
  5. <legend>DO YOU KNOW</legend>
  6. <!-- one field start -->
  7.  <div class="field50Pct">
  8.                     <div class="fieldItemLabel">
  9.                             <label for="What is Diabetes">What is Diabetes:</label>
  10.                     </div>
  11.                     <div class="fieldItemValue">
  12.  
  13.  <?php
  14. if($_POST['what_is_diabetes']=='YES'){
  15. $chk1="checked";
  16. }
  17.  
  18. ?>
  19.  
  20. <input onclick="EnableDisableDIV(this.id,'hide1')" type="checkbox" name="what_is_diabetes" id="what_is_diabetes" value="YES" <?php echo $chk1 ?>> <span class="star">*</span>
  21.                     </div>
  22.             </div>
  23. <?php 
  24. if(isset($_POST['what_is_diabetes'])){
  25. echo "<div id='hide1'>";
  26. }
  27. else {
  28. echo "<div id='hide1' style='display:none'>";
  29. ?>
  30.             <div class="field50Pct">
  31.  
  32.                     <div class="fieldItemLabel">
  33.                             <label for=''>&nbsp;&nbsp;</label>
  34.                     </div>
  35.                     <div class="fieldItemValue">
  36. <input type="text" id="diabetes_date" name="diabetes_date" value="<?php $_POST['diabetes_date'] ?>" />
  37. <div id="cal">
  38. <a href="javascript:NewCssCal('diabetes_date','yyyymmdd')">
  39. <img src="/sample/images/cal.gif" width="16" height="16" alt="Pick a date"></a>
  40. </div>
  41.                     </div>
  42.             </div>
  43. </div>
  44.  
  45.             <div class="clear"></div>
  46. <!-- one field end -->
  47.  

and here is page.css

Expand|Select|Wrap|Line Numbers
  1.  function EnableDisableDIV(fieldid,divid) {
  2.               if ($("#"+fieldid).attr("checked")) {
  3.  
  4.                   $("#"+divid).show('slow');
  5.  
  6.               } else {
  7.  
  8.               $("#"+divid).hide('slow');
  9.  
  10.               }
  11.  
  12.           }
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,648
#2: Oct 12 '09

re: form problem


Quote:

Originally Posted by pradeepjain View Post

but when i refresh the page the text box gets hidden and the value is also lost ...

this is the normal behaviour. you can do nothing about that with javascript alone. if you want to retain the data, you have to do it server side (and probably with the help of the onbeforeunoad event)
Tarantulus's Avatar
Member
 
Join Date: May 2007
Posts: 103
#3: Oct 12 '09

re: form problem


I see you have a little PHP in there, have you tried using a session variable to record the state of the button?
pradeepjain's Avatar
Needs Regular Fix
 
Join Date: Jul 2007
Location: India
Posts: 407
#4: Oct 12 '09

re: form problem


Quote:

Originally Posted by Tarantulus View Post

I see you have a little PHP in there, have you tried using a session variable to record the state of the button?

nope!! i havent tried that!! can you just tell me how to do it using sessions!
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,648
#5: Oct 12 '09

re: form problem


a look in the manual should be the first thing to do.
pradeepjain's Avatar
Needs Regular Fix
 
Join Date: Jul 2007
Location: India
Posts: 407
#6: Oct 12 '09

re: form problem


okie!! i will go through it !! i have another doubt in same form .. when error occurs in this form say spme field error !! i display the errors from server side validation . How do i keep the form field which i enabled(showed) using jquey method bcos its an onclick action on which i display the field!
Reply