2 Replies - 1405 Views - Last Post: 03 June 2012 - 10:57 PM

#1 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

How can i trigger the submitHandler without the submit button?

Posted 03 June 2012 - 07:55 PM

the submit button can trigger the submitHandler,.. i want to submit a form without refreshing so I use this. but it only activates when i use the submit button.. I put onclick="document.ShareIndividually.submit();" in my checkboxes but the page refreshes when submitting a form..







<script src="SpryAssets/SpryCollapsiblePanel.js" type="text/javascript"></script>
<script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<script src="jQuery v1.7.2 jquery.js" type="text/javascript"></script>
<script src="jQuery validation plug-in 1.7.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function(){
		$("#ShareIndividually").validate({
			debug: false,
			rules: {
				name: "required",
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				name: "Please let us know who you are.",
				email: "A valid email will help us get in touch with you.",
			},
			
			submitHandler: function(form){
				// do other stuff for a valid form
				$.post('ShareIndividually.php', $("#ShareIndividually").serialize(), function(data) {
					$('#ShareIndividuallyResults').html(data);
				});
			}
		});
	});

</script>


<div class="TabbedPanelsContent"><!--START of content number 1-->
    
    <div id="ShareIndividuallyResults">
   
    </div>
    	<form action="" method="post" name="ShareIndividually" id="ShareIndividually">
    <div style="overflow:scroll; height:270px;"> <!-- For CSS Overflow-->
    	<?php
         $DocID = $_GET['DocID'];
		 $USERNAME = $UserName;
		?>
        

				        
        <input type = 'hidden' value="<?php echo $DocID; ?>" name='DocID'>
        <input type = 'hidden' value="<?php echo $USERNAME; ?>" name='USERNAME'>
        
        <table id="IndividualList" cellpadding="5" width="400">
           <tr style="background-color:black; color:white; font-weight:bold;">
                <td></td> 
                <td width="200">Name of Staff</td>
                <td  width="150">Institution</td>
           </tr>
           <?php 
		   	$DocID = $_GET['DocID'];
			//START GET USERNAME ID 
			$UserName = $_GET['USERNAME'];
			$queryUserID = "select UserID from Users where UserName='$UserName'";
 			$resultUserID = mssql_query($queryUserID);
			while($r4=mssql_fetch_array($resultUserID))
			{
				 $UserID222222 = $r4['UserID'];
				
			}
			//END USERNAME ID
			$query_individual = "select u.FName,u.LName,i.InstitutionName,u.UserID,u.PositionID,u.Userlevel from Users u inner join Institutions i on i.InstitutionID=u.InstitutionID";
			$result_individual = mssql_query($query_individual);
			$color="1";
			while($r=mssql_fetch_array($result_individual))
			 {
				$FullName=  $r[FName]." ".$r[LName];
				$Institution = $r[InstitutionName];
				$SharedUserID = $r[UserID];
				$DocID;
				$PositionID = $r[PositionID];
				$Userlevel = $r[Userlevel];
				
				//for editting purpose
				$query_user_if_shared_already = "Select * from Share_Doc where Shared_To='$SharedUserID' and DocID='$DocID' and uploader='$UserID222222'";
				$result_user_if_shared_already = mssql_query($query_user_if_shared_already) or die('cannot query if user is already shared');
				while($r9=mssql_fetch_array($result_user_if_shared_already)){
					$r9[Shared_To];
					$r9[DocID];
				
					}
				$result_user_if_shared_already_num_rows  = mssql_num_rows($result_user_if_shared_already);
				//for editting purpose
			?>
			
            <?php 
			 //START submit button is executed for individual
			 if(isset($_POST['submit']))
			 {
				if(isset($_POST['Individual'.$SharedUserID.''])) 
				{
				$query_to_make_it_not_redundant="Select * from Share_Doc where DocID='$DocID' and uploader='$UserID222222' and Shared_To='$SharedUserID' and PositionID='$PositionID'";
				$result_to_make_it_not_redundant = mssql_query($query_to_make_it_not_redundant);
				$numrows_to_make_it_not_redundant = mssql_num_rows($result_to_make_it_not_redundant);
				  
				  if($numrows_to_make_it_not_redundant=="0")
				  {	
				  $query_share_insert = "insert into Share_Doc values ('$DocID','$UserID222222','$SharedUserID','$PositionID','$Userlevel')";
				  $result_share_insert = mssql_query($query_share_insert) or die('cannot share');
					
					//START For Notification
				   $textNotification = $_GET['USERNAME']." shared ".$DocID." with you.";
				   $Noti_friend_being_shared = $SharedUserID;
				   $status = '1';
				   
					$result = MSSQL_QUERY("Exec usp_Notifications '$textNotification','$Noti_friend_being_shared','$status'")or die('wah');
					//END for Notification
					
				  }
				}elseif(!isset($_POST['Individual'.$SharedUserID.''])) {
					$query_delete_individual_if_unchecked ="DELETE FROM Share_Doc WHERE DocID='$DocID' and Shared_To='$SharedUserID' and uploader='$UserID222222' and PositionID='$PositionID'";
					$result_delete_individual_if_unchecked = mssql_query($query_delete_individual_if_unchecked);
					}//else command if if variable is not set
			 }//End if Submit
			 //END submit button is executed for individual
			 ?>
                 
             <?php 
           // declaration of the color for alternative colors of each rows in the table
          
           if($color=="1"){
           ?>
             <tr bgcolor="#FFFFFF">	
                <td><input type="checkbox" name="Individual<?php echo $SharedUserID;?>" value="yes" <?php if($result_user_if_shared_already_num_rows!='0'){ echo 'checked';}?>  onclick="document.ShareIndividually.submit();"    ></td> 
                <td><?php echo $FullName; ?></td>
                <td><?php echo $Institution; ?></td>
             </tr>
            <?php
				 $color="2";
				 
				 }else{
			?>
			 <tr bgcolor="#CCCCCC">	
                <td><input type="checkbox" name="Individual<?php echo $SharedUserID;?>" value="yes" <?php if($result_user_if_shared_already_num_rows!='0'){ echo 'checked';}?>   onclick="document.ShareIndividually.submit();"   ></td> 
                <td><?php echo $FullName; ?></td>
                <td><?php echo $Institution; ?></td>
             </tr>
             
			 
			 <?php
			 
			$color="1";
				 }
					 $UserID222222.'<br>';		
			 ?>
			 
			
             
     <?php
		}//end of while loop sharing
	  ?>
        </table>
        
        </div><!-- END for the css overflow-->
   
   </form>
    </div><!--END of content number 1-->




Is This A Good Question/Topic? 0
  • +

Replies To: How can i trigger the submitHandler without the submit button?

#2 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

Re: How can i trigger the submitHandler without the submit button?

Posted 03 June 2012 - 08:45 PM

[link]

http://www.askaboutp...2#comment-84658

[/link]

i use this tutorial to do submitting without refreshing but it uses a submit button to do that what i need is to submit a form by only just checking the checkbox
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,044
  • Joined: 08-June 10

Re: How can i trigger the submitHandler without the submit button?

Posted 03 June 2012 - 10:57 PM

you canít submit a form without refreshing the page. thatís how forms work. if you donít want that, use AJAX, but then you have to fetch and prepare the data to send yourself.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1