How to Pass values from a php via java script to HTML elements

<!doctype html>
 <?php  
   /*-----------------------------------CONNECTIVITY CODE-----------------------------------*/
     error_reporting(E_ERROR | E_PARSE);      //optional,to remove warning messages.
     $conn=mysqli_connect("localhost","root","","codershelpline");
        if ($conn)
          {
           echo "database connected successfully","<br>";
          }
        else
          {
           die("Connection Aborted:" . mysqli_connect_error());
          }
    /*------- VALUE TRNASFER FROM HTML TO PHP TRANSFER CODE------*/

    $TxtSlno1=$_REQUEST['TxtSlno'];
    $TxtSname1=$_REQUEST['TxtSname'];
    $TxaAddr1=$_REQUEST['TxaAddr'];
    $Rdbsex1=$_REQUEST['Rdbsex'];
    $TxtUname1=$_REQUEST['TxtUname'];
    $TxtPassword1=$_REQUEST['TxtPassword'];
    $DtpDob1=$_REQUEST['DtpDob'];
    $TxtMobno1=$_REQUEST['TxtMobno'];
    $TxtEmail1=$_REQUEST['TxtEmail'];	
    $CmbSecQues1=$_REQUEST['CmbSecQues'];
    $TxtSecAns1=$_REQUEST['TxtSecAns'];
    $ChkCricket1=$_REQUEST['ChkCricket'];	
    $ChkDance1=$_REQUEST['ChkDance'];
    $ChkMusic1=$_REQUEST['ChkMusic'];	
    $TxtRem1=$_REQUEST['TxtRem']; 

    $p=0; 
   		
/*-------------------------------------SEARCH CODE------------------------------------*/
$SearchBx1=$_REQUEST['SearchBx'];
if(isset($_REQUEST['BtnSrc']))
{			
   $query2="select * from chlsave where TxtSlno4='$SearchBx1'";
   $result=mysqli_query($conn,$query2);
  
   while($row1=mysqli_fetch_array($result))
  {
    $TxtSlno3=$row1['TxtSlno4'];
    $TxtSname3=$row1['TxtSname4'];
    $TxaAddr3=$row1['TxaAddr4'];
    $Rdbsex3=$row1['Rdbsex4'];
    $TxtUname3=$row1['TxtUname4'];
    $TxtPassword3=$row1['TxtPassword4'];
    $DtpDob3=$row1['DtpDob4'];
    $TxtMobno3=$row1['TxtMobno4'];
    $TxtEmail3=$row1['TxtEmail4'];	
    $CmbSecQues3=$row1['CmbSecQues4'];
    $TxtSecAns3=$row1['TxtSecAns4'];
    $ChkCricket3=$row1['ChkCricket4'];	
    $ChkDance3=$row1['ChkDance4'];
    $ChkMusic3=$row1['ChkMusic4'];	
    $TxtRem3=$row1['TxtRem4'];

    global $p;    
    $p=1;  
  }
}		
?> 
   
<!--------------------------------HTML DESIGN CODE------------------------------------->    
<html>
   <head>
      <title>Codershelpline Code for display html value</title>
      
      <script>      
         Function input()
          {
           var x = "<?php echo $p;?>";              
           if(x==1)
             { 
               var y = "<?php echo(“Codershelpline”); ?>";
               var a = "<?php echo $m; ?>"; 
               var b = "<?php echo $k; ?>"; 
               var c = "<?php echo $password; ?>"; 
               var d = "<?php echo $mobile; ?>"; 
               var e = "<?php echo $dob; ?>"; 
               var f = "<?php echo $sex; ?>"; 
               var g = "<?php echo $country; ?>"; 
               var h = "<?php echo $cricket; ?>";
               vari = "<?php echo $dance; ?>";
               var j = "<?php echo $music; ?>";
               var k = "<?php echo $surfing; ?>";
      </script>

   </head>
   <body>
      <form name="form1" id="form2" action="#" method="post" >
	 <center>
	    <fieldset style="width: 600px">				
		<legend>Create New Student Account</legend>
		   <table>
		      <tr>
			  <td>Serial No.</td>
			  <td>:</td>
			  <td><input type="text" name="TxtSlno" value="<?php echo $TxtSlno3;?>"></td>
			  <td>Search Box</td>
			  <td>
			     <select name="SearchBx" id="SearchBx">									
				<option>---Select---</option>
				<?php
				   $res=mysqli_query($conn,"select TxtSlno4 from chlsave");
				      while($row=mysqli_fetch_array($res))
				      {
				?>
					<option value="<?php echo $row['TxtSlno4'];?>"><?php echo 
                                           $row['TxtSlno4'];?></option>
				<?php
				      }
				?>
                             </select>
			  </td>
		      </tr>
		      <tr>
			  <td>Student Name</td>
			  <td>:</td>
			  <td><input type="text" name="TxtSname" value="<?php echo $TxtSname3;?>">
                          </td>
		      </tr>
		      <tr>
			  <td>Address</td>
			  <td>:</td>
			  <td>
			    <textarea cols="35" rows="5" name="TxaAddr"><?php echo $TxaAddr3;?>
                            </textarea>							
			  </td>
		       </tr>
		       <tr>
			  <td>Sex</td>
			  <td>:</td>
		          <td>				  
			     <?php											
				if($Rdbsex3==="Male")
				{
				   $Gen1="checked";
				}	
				if($Rdbsex3==="Female")
				{
				   $Gen2="checked";
				}
				if($Rdbsex3==="Other")
				{
				   $Gen3="checked";
				}
			      ?>				  
		              <input type="radio" name="Rdbsex" id="RdbMale" <?php echo $Gen1;?> 
                                 value="Male">Male
		              <input type="radio" name="Rdbsex" id="RdbFemale" <?php echo $Gen2;?> 
                                 value="Female">Female
		              <input type="radio" name="Rdbsex" id="RdbOther" <?php echo $Gen3;?>
                                 value="Other">Other
		          </td>

		       </tr>						
		       <tr>
			  <td>User Name</td>
			  <td>:</td>
			  <td><input type="text" name="TxtUname" value="<?php echo $TxtUname3;?>">
                          </td>
		       </tr>
		       <tr>
			  <td>Password</td>
			  <td>:</td>
			  <td><input type="password" name="TxtPassword" value="<?php echo 
                             $TxtPassword3;?>"></td>
		       </tr>
		       <tr>
			  <td>Confirm Password</td>
			  <td>:</td>
			  <td><input type="password" name="TxtCpassword" value="<?php echo 
                             $TxtCpassword3;?>"></td>
		       </tr>
		       <tr>
		          <td>DOB</td>
			  <td>:</td>
			  <td><input type="date" name="DtpDob" value="<?php echo $DtpDob3;?>"></td>
		       </tr>
		       <tr>
			  <td>Mobile No.</td>
			  <td>:</td>
			  <td><input type="Number" name="TxtMobno" value="<?php echo $TxtMobno3;?>">
                          </td>
		       </tr>
		       <tr>
			  <td>Email</td>
			  <td>:</td>
			  <td><input type="text" name="TxtEmail" value="<?php echo $TxtEmail3;?>">
                          </td>
		       </tr>					
		       <tr>
			  <td>Security Questions</td>
			  <td>:</td>
			  <td>		  
			     <?php										
				if($CmbSecQues3==="What is Your Favourite Book")
				{
				   $SecQues1="selected";
				}
				if($CmbSecQues3==="What is Your Favourite Teacher")
				{
				   $SecQues2="selected";
				}
				if($CmbSecQues3==="What is Your Favourate Place")
				{
				   $SecQues3="selected";
				}
				if($CmbSecQues3==="What is Your Favourate Pets")
				{
				   $SecQues4="selected";
				}
			     ?>			  
                             <select name="CmbSecQues">
                                <option value="Choose One">Choose One</option>
                                <option <?php echo $SecQues1;?> value="What is Your Favourite Book">
                                   What is Your Favourite Book</option>
                                <option <?php echo $SecQues2;?> value="What is Your Fav. Teacher">
                                   What is Your Favourite Teacher</option>
                                <option <?php echo $SecQues3;?> value="What is Your Favourate Place">
                                   What is Your Favourate Place</option> 
                                <option <?php echo $SecQues4;?> value="What is Your Favourate Pets">
                                   What is Your Favourate Pets</option>
                             </select>
			  </td>
		     </tr>
		     <tr>
			<td>Security Answer</td>
			<td>:</td>
			<td><input type="text" name="TxtSecAns" value="<?php echo $TxtSecAns3;?>">
                        </td>
		     </tr>
		     <tr>
			<td>Hobbies</td>
			<td>:</td>
			<td>			
			   <?php										
				if($ChkCricket3==="Cricket")
				{
				   $Ckt="checked";
				}
				if($ChkDance3==="Dance")
				{
				   $Dnc="checked";
				}
				if($ChkMusic3==="Music")
				{
				   $Msc="checked";
				}
			   ?>				
			   <input type="checkbox" name="ChkCricket" <?php echo $Ckt;?> value=
                              "Cricket">Cricket
			   <input type="checkbox" name="ChkDance" <?php echo $Dnc;?> value=
                              "Dance">Dance
			   <input type="checkbox" name="ChkMusic" <?php echo $Msc;?> value=
                              "Music">Music			   
			</td>
		     </tr>
		     <tr>
			<td>Remarks</td>
			<td>:</td>
			<td><input type="text" name="TxtRem" value="<?php echo $TxtRem3;?>"></td>
		     </tr>
		     <tr>
			<td></td>
			<td></td>
			<td><input type="submit" name="BtnSave" value="Save">
			    <input type="reset" name="BtnReset" value="Reset">
			    <input type="submit" name="BtnDel" value="Delete">
			    <input type="submit" name="BtnSrc" value="Search">
			    <input type="submit" name="BtnUpd" value="Update">
			</td>
		     </tr>

		  </table>
	      </fieldset>
            </center>
	  </form>
        </body>
      </html>

Loading

Categories: Php Proj

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.