form problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    form problem

    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.

    Code:
    <script type="text/javascript" src="/JS/page.js"></script>
    <form name="test123" id="test2" method="POST">  
    <div class="fieldForm" id="fieldForm" >
    <fieldset id="personnel">
    <legend>DO YOU KNOW</legend>
    <!-- one field start -->
     <div class="field50Pct">
                        <div class="fieldItemLabel">
                                <label for="What is Diabetes">What is Diabetes:</label>
                        </div>
                        <div class="fieldItemValue">
                   
     <?php
    if($_POST['what_is_diabetes']=='YES'){
    $chk1="checked";
    }
    
    ?>
    
    <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>
                        </div>
                </div>
    <?php 
    if(isset($_POST['what_is_diabetes'])){
    echo "<div id='hide1'>";
    }
    else {
    echo "<div id='hide1' style='display:none'>";
    } 
    ?>
                <div class="field50Pct">
    
                        <div class="fieldItemLabel">
                                <label for=''>&nbsp;&nbsp;</label>
                        </div>
                        <div class="fieldItemValue">
    <input type="text" id="diabetes_date" name="diabetes_date" value="<?php $_POST['diabetes_date'] ?>" />
    <div id="cal">
    <a href="javascript:NewCssCal('diabetes_date','yyyymmdd')">
    <img src="/sample/images/cal.gif" width="16" height="16" alt="Pick a date"></a>
    </div>
                        </div>
                </div>
    </div>
    
                <div class="clear"></div>
    <!-- one field end -->

    and here is page.css

    Code:
     function EnableDisableDIV(fieldid,divid) {
                  if ($("#"+fieldid).attr("checked")) {
    
                      $("#"+divid).show('slow');
    
                  } else {
    
                  $("#"+divid).hide('slow');
    
                  }
    
              }
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by pradeepjain
    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)

    Comment

    • Tarantulus
      New Member
      • May 2007
      • 114

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

      Comment

      • pradeepjain
        Contributor
        • Jul 2007
        • 563

        #4
        Originally posted by Tarantulus
        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!

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          a look in the manual should be the first thing to do.

          Comment

          • pradeepjain
            Contributor
            • Jul 2007
            • 563

            #6
            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!

            Comment

            Working...