creating a sticky form compatible with onChange

Discussion in 'PHP' started by assgar, Mar 26, 2008.

  1. #1
    Hi

    I was using PHP sessions to create a sticky form but a
    button was needed to reload the page.

    I am new to Java and I have decided to do away with the button.
    Using onChange="javascript:OnChange(this) to cause the
    page to reload once a selection is made from a dynamic dropdown works.

    The problem is the input box and other dropdown on the same page lose
    their information. How can I create a sticky form that is
    compatible with onChange?


    Thanks



    
    
    <?
     include("../priority_low_to_high_in.php");//proiority drop down
    ?>
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Calendar</title>
    <link href="../config.css" rel="stylesheet" type="text/css"/>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function OnChange(dropdown)
    {
      window.location.href="http://localhost/search_form.php?pro_id=" +
      dropdown.options[dropdown.selectedIndex].value;
    }
    
    
    function MM_reloadPage(init) 
     {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
     }
    MM_reloadPage(true);
    //-->
    </script>
    
    <style type="text/css">
    <!--
    
    -->
    </style>
    </head>
    
    <!-----------------------form processor---------------------------->
    <form  action="../search_process.php" name="calendar" method="post">
    
    <tr>
     <td>
          <select name= "provider_id" onChange="javascript:OnChange(this);">
           <?   
     	    //display lastname and first name 
     	    provider_first_last_name_display($name, $name_val, $db_id);
           	?>
          </select>
     </td>
    </tr>
    
    <tr>
      <td>
        <!---reason input---->
        <input type="text" name="reason" size="30" maxlength="60" value ="<?php echo $reason; ?>">
      </td>
    </tr>
    
    <tr>
      <td>
      	 <!--priority dropdown-->
      	 <select name="priority">
    	 <?php
    	    $priority_name = get_b_priority_name($b_priority_n);
    	    $priority_code = get_b_priority_code($b_priority_c);
    	    for($n = 1; $n<= 6; $n++)
    	        {
    		   $sname = $priority_name[$n];
    		   $scode = $priority_code[$n];
    		   echo "<option value = '$scode'";
    		      if ($scode == " ")
    		          {
    		               echo "selected";
    		          }
    		   echo "> $sname";
    		}
    	 ?>
             </select>
      </td>
    </tr>
    </body>
    </from>
    </html>
    
    
    PHP:
     
    assgar, Mar 26, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    use ajax.. here are some articles

    http://www.w3schools.com/ajax/default.asp

    another thing, dont trust javascript on handling your varibles, if you can do it in php then why not php..
    some of these lost variables are made by java due to some browsers compatibility
     
    bartolay13, Mar 26, 2008 IP
  3. assgar

    assgar Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi

    Thanks for responding.

    I hear you. I would prefer Php and tried both approaches:

    
    <input type="text" name="reason" size="30" maxlength="60" value="<?php $_POST['reason'?>">
    
    
    <input type="text" name="reason" size="30" maxlength="60"   value="<?php if(!empty($_POST['reason'])){echo $_POST['reason'];} else{echo"$reason";}?>">
    
    PHP:
    But the input box looses its contents. What am I missing?
     
    assgar, Mar 29, 2008 IP
  4. Xtrm2Matt

    Xtrm2Matt Active Member

    Messages:
    129
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Are these on the page where you enter the data, or the page after?

    First one won't work because it should be $_POST["reason"], and neither of them would work anyway presuming you're using these on the page where you submit the data.

    Try this:

    
    <input type="text" name="reason" size="30" maxlength="60" value="<?= $_POST['reason'] ?>">
    
    PHP:
    This will automatically set the value to the data you enter in the "Reason" text input box.
     
    Xtrm2Matt, Mar 29, 2008 IP
  5. assgar

    assgar Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I only use one input for reason. These are the two attemps I have tried.
    The data collection boxes are on the same page that is reloaded.
     
    assgar, Mar 30, 2008 IP