Clear data after click on the submit button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Clear data after click on the submit button

    I' using php ,mysql and ajax. I want to add vehicles details to the database. data adding part is working. But the problem is text fields are not clear after the submit. This is my code
    Code:
    <?php 
    session_start();
    require_once ('dbconnect.php');
    require_once ('commonFunctions.php');
     ?>
    
    <script language="javascript" src="ajax.js"></script>
    </head>
    <div id="addvehicle"></div>
    <?
    //----------------get selecteddropdown value from ajax and pass to the getVehicleModel Fn in commonFunction.php-----
    $make= "";
    
    
    if(isset($_GET['Submit'])==2){
    	$make=$_GET['make'];
    	getVehicleModel($make);
    	return;
    }	
    if(isset($_GET['St'])==1){
    	$make=$_GET['make'];
    	$model=$_GET['model'];
    	$type=$_GET['type'];
    	$year=$_GET['year'];
    	$month=$_GET['month'];
    	$fuel=$_GET['fuel'];
    	$transmission=$_GET['transmission'];
    	$displacement=$_GET['displacement'];
    	$color=$_GET['color'];
    	$milage=$_GET['milage'];
    	$price=$_GET['price'];
    	$other=$_GET['other'];
    //---------------------insert data to vehicles table-------------------------------------------	
    	$sql = "INSERT INTO vehicles VALUES('','$make','$model','$type','$year','$month','$fuel','$transmission','$color','$price','$displacement','$milage','$other')";
    
    $result = mysql_query($sql);
    	
    if (!$result) 
    {
    echo "Error in SQL query: " . mysql_error();
    }
    else{
    echo "success";	}
    
    	return;
    	}
    ?>
    
    
    
    <table width="566" height="100%" border="0" align="center" cellpadding="0" cellspacing="0"  >
     
      
    
    <tr>
    <td>
    <table cellspacing="5"><br />
    <tr><td colspan="2"></td></tr>
    
    <tr>
    <td>Make :</td> 
    <td>
    <?php getVehicleMake(); 
    ?>			
    </td>
    
    </tr>
    					<tr>
    <? //------------------ this is reciveing ajax sending selected vahicle make-------------------------- ?>					
    <!--<div id='txtHint'></div>-->
    <td>Model :</td> 
    <td>
    <div id='txtHint'>
    <?					getVehicleModel($make);
    ?>
    </div>		
    </td>
    </tr>
    <tr>
    <td>Type :</td> 
    <td colspan="3">
    <? getVehicleType();?>
    </td>
    </tr>
    
    <tr>
    <td>Other :</td> <td><textarea id="Other" cols=40 rows=3  name="Other" class="normalTxt" ></textarea></td>
    </tr>
    <tr>
    
    </tr>
    				
    <tr>
    <td align="right" colspan="2"><input type="image"  class="btn"  src="images/addBtn.jpg" alt="Search"  name="submit" onclick="addVehicle(); return false;" />
    					</td>
    				</tr>
    			</table>
    			
    		</td>
    	</tr>
     	
    	
    </table>
    
    </body>
    </html>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    when you’re using AJAX, you don’t submit the form, you do stuff in the background. thus you have to clear the fields yourself (manually).

    Comment

    • ghjk
      Contributor
      • Jan 2008
      • 250

      #3
      Thanx. I have Written the following code in ajx page. Then all the other fields are reset without Model field. Please tell me what is the problem with that?
      Code:
      document.test.reset();

      Comment

      • ghjk
        Contributor
        • Jan 2008
        • 250

        #4
        I have done it. But I don't know whether is it the correct way. But my code is working.
        Code:
        document.test.reset();
        			document.getElementById('Model').selectedIndex  = 0;

        Comment

        • Chris T
          New Member
          • Jul 2011
          • 5

          #5
          easier way would be using jquery. just use $('name_of_fiel d_to_clear').va l('');
          You set it's value to '' and clear any field you want.

          Comment

          Working...