Page 1 of 1
How to assign a textbox value to PHP variable??
Posted: Fri Oct 30, 2009 4:35 am
by juniorjel
Hi ! Can any one help me out as quickly as possible. As I m new to PHP.
Plz tell me how to assign a textbox value to PHP variable on a same PHP page with out POSTING data to other page e.g:
$tbVal = textbox;
I dont want to do this ----> $tbVal = $_POST[""];
pLZ HELP ME OUT ON THIS.
Re: How to assign a textbox value to PHP variable??
Posted: Fri Oct 30, 2009 4:56 am
by cpetercarter
It would be easier to help if you explained in more detail why you want to achieve this.
Remember that PHP runs on your server. It therefore does not know what value your user has put into the textbox until the user presses the submit button and sends the $_POST data to the server. So the simple answer to your question is that you cannot do what you say you want.
JavaScript however runs on the browser, not the server. You can use JavaScript to read the text which the user has put in the textbox, and either sanity-check it, or compute something from it (eg number of words), or display it somewhere else on the webpage. It might be possible - depending on what you want to do - to send the textbox text back to the server using Ajax, and return some values computed on the server.
Re: How to assign a textbox value to PHP variable??
Posted: Fri Oct 30, 2009 6:45 am
by guru2k9
Hi
Use the below code on the top of html open tag
<?php
if(isset($_POST[buttonname]))
{
$textarea=$_POST[textareaname];
}
?>
Thanks
Re: How to assign a textbox value to PHP variable??
Posted: Fri Oct 30, 2009 2:08 pm
by juniorjel
HI cpetercarter ! Thanks for replay
I am not using Submit button in my form as i dont want to submit data on other php page. I m using a javascript function that hide a div on a button click and that div contains the person information then it shows a div that contains the data that user has searched for. If i use submit button the javascript dosent work. If i use simple button then the javascript function work. Thats y i dont want to use submit button.
Re: How to assign a textbox value to PHP variable??
Posted: Fri Oct 30, 2009 2:14 pm
by juniorjel
Thanks a lot guru !
But thts not wt i want
Re: How to assign a textbox value to PHP variable??
Posted: Fri Oct 30, 2009 2:15 pm
by juniorjel
<?php
include('../library/connect.php');
$Pinfoqry = mysql_query("SELECT personinfoID,FirstName,LastName,PersonMobile,PersonType,Status FROM tblpersoninfo");
$numrows = mysql_num_rows($Pinfoqry);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Personal Information</title>
<style type="text/css">
<!--
body {
background-image: url(../images/main.JPG);
}
.style1 {
color: #FFFFFF;
font-weight: bold;
}
.style2 {color: #00FF00}
.style6 {color: #999999}
.style7 {
font-size: x-large;
font-weight: bold;
color: #000099;
}
-->
</style>
<script type="text/javascript">
function ShowHideFPddl()
{
var PTddl = document.getElementById("ddlFPpersonType");
if(PTddl.value == "Allpt")
{
document.getElementById("ddlFPsearchByAll").style.display = "block";
document.getElementById("ddlFPsearchByStudent").style.display = "none";
document.getElementById("ddlFPsearchByTeacher").style.display = "none";
document.getElementById("ddlFPsearchByAdmin").style.display = "none";
}
else if(PTddl.value == "Student")
{
document.getElementById("ddlFPsearchByAll").style.display = "none";
document.getElementById("ddlFPsearchByStudent").style.display = "block";
document.getElementById("ddlFPsearchByTeacher").style.display = "none";
document.getElementById("ddlFPsearchByAdmin").style.display = "none";
}
else if(PTddl.value == "Teacher")
{
document.getElementById("ddlFPsearchByAll").style.display = "none";
document.getElementById("ddlFPsearchByStudent").style.display = "none";
document.getElementById("ddlFPsearchByTeacher").style.display = "block";
document.getElementById("ddlFPsearchByAdmin").style.display = "none";
}
else if(PTddl.value == "Admin")
{
document.getElementById("ddlFPsearchByAll").style.display = "none";
document.getElementById("ddlFPsearchByStudent").style.display = "none";
document.getElementById("ddlFPsearchByTeacher").style.display = "none";
document.getElementById("ddlFPsearchByAdmin").style.display = "block";
}
else
{return false;}
}
function ShowHideDiv()
{
var FPval = document.getElementById("ddlFPpersonType").value;
if(FPval == "Allpt")
{
document.getElementById("divPinfo").style.display = "none";
document.getElementById("divPTAllFPR").style.display = "block";
}
else
{
document.getElementById("divPinfo").style.display = "block";
document.getElementById("divPTAllFPR").style.display = "none";
}
}
</script>
</head>
<body>
<form name="filterPerson" id="filterPerson">
<table width="494">
<tr>
<td width="148"><div align="left">Filter
<select name="ddlFPpersonType" id = "ddlFPpersonType">
<option value="Allpt" onclick = "ShowHideFPddl();">All</option>
<option value="Student" onclick ="ShowHideFPddl();">Student</option>
<option value="Teacher" onclick = "ShowHideFPddl();">Teacher</option>
<option value="Admin" onclick = "ShowHideFPddl();">Admin</option>
</select>
by</div></td><td width="126"><select name="ddlFPsearchByAll" id = "ddlFPsearchByAll">
<option value="Allsb">All</option>
<option value="AllName">Name</option>
<option value="AllUname">UserName</option>
<option value="Allstatus">Status</option>
</select>
<select name="ddlFPsearchByStudent" id = "ddlFPsearchByStudent" style = "display:none">
<option value="Studentsb">All</option>
<option value="StudentName">Name</option>
<option value="StudentUname">UserName</option>
<option value="StudentReg">Reg #</option>
<option value="StudentDept">Department</option>
<option value="StudentSemester">Semester</option>
<option value="Studentstatus">Status</option>
</select>
<select name="ddlFPsearchByTeacher" id = "ddlFPsearchByTeacher" style = "display:none">
<option value="Teachersb">All</option>
<option value="TeacherName">Name</option>
<option value="TeacherUname">UserName</option>
<option value="TeacherReg">Reg #</option>
<option value="TeacherDept">Department</option>
<option value="TeacherTtype">Teacher Type</option>
<option value="TeacherDesig">Designation</option>
<option value="Teacherstatus">Status</option>
</select>
<select name="ddlFPsearchByAdmin" id = "ddlFPsearchByAdmin" style = "display:none">
<option value="Adminsb">All</option>
<option value="AdminName">Name</option>
<option value="AdminUname">UserName</option>
<option value="AdminPost">Post</option>
<option value="Adminstatus">Status</option>
</select></td><td width="144"><input type="text" name="txtFPSearchQuery" id="txtFPSearchQuery" /></td>
<td width="56"><input type="Button" name="btnsearch" id="btnsearch" value="Search" onclick = "ShowHideDiv()";/></td>
</tr>
</table>
<div id = "divPinfo">
<table align='center' width="662" border="2">
<tr>
<td colspan="8" align ="center"><font size="5" face="Georgia, Arial" color="maroon">Personal Information</font></td>
</tr>
<tr>
<td colspan="8"><a href = "AddPerson.php">Add Person</a></td>
</tr>
<tr>
<td bgcolor="#3333CC"><div align="center" class="style1">
<div align="center">Sr#</div>
</div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">First Name </span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Last Name</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Phone#</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Person Type</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Status</span></div></td>
<td bgcolor="#FFFFFF"><div align="center">Edit</div></td>
<td bgcolor="#FFFFFF"><div align="center">Delete</div></td>
</tr>
<?
if($numrows>0)
{ $i=1; while($row_fetch=mysql_fetch_array($Pinfoqry))
{ $StatusLook = $row_fetch['Status'];
if($StatusLook == '1')
{$SL = 'Active';}
else
{$SL = 'Unactive';}
?>
<tr>
<td width="45" bgcolor="#33CCFF"><?=$i?></td>
<td width="70" bgcolor="#33CCFF"><?=$row_fetch['FirstName']?></td>
<td width="73" bgcolor="#33CCFF"><?=$row_fetch['LastName']?></td>
<td width="78" bgcolor="#33CCFF"><?=$row_fetch['PersonMobile']?></td>
<td width="76" bgcolor="#33CCFF"><?=$row_fetch['PersonType']?></td>
<td width="72" bgcolor="#33CCFF"><?=$SL?></td>
<td width="56" bgcolor="#FFFFFF"><a href = 'EditPerson.php'>Edit</a></td>
<td width="138" bgcolor="#FFFFFF"><a href = 'DeletePerson.php'>Delete</a></td>
</tr>
<? $i++; }
}else
{
die("No Record");
}?>
</table>
</div>
<div id = "divPTAllFPR" style = "display:none">
<table border="2">
<tr>
<td colspan="8" align ="center"><font size="5" face="Georgia, Arial" color="maroon">Search Result</font></td>
</tr>
<tr>
<td colspan="8"><a href = "AddPerson.php">Add Person</a></td>
</tr>
<tr>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Sr#</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Person Type</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Full Name </span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">UserName</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Phone#</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Status</span></div></td>
<td bgcolor="#FFFFFF"><div align="center">Edit</div></td>
<td bgcolor="#FFFFFF"><div align="center">Delete</div></td>
</tr>
<?
$qryFP_all2all = mysql_query("SELECT PersonType, FirstName, LastName, UserName, PersonMobile, Status FROM tblpersoninfo WHERE FirstName LIKE '%$tbsq%' OR LastName LIKE '%$tbsq%' OR UserName LIKE '%$tbsq%'");
$numrows_FPall2all = mysql_num_rows($qryFP_all2all);
if($numrows_FPall2all>0)
{ $i=1; while($row_fetch_allFP=mysql_fetch_array($qryFP_all2all))
{ $StatusLook_all = $row_fetch_allFP['Status'];
if($StatusLook_all == '1')
{$SL_all = 'Active';}
else
{$SL_all = 'Unactive';}
$fnameFP_all2all = $row_fetch_allFP['FirstName'];
$lnameFP_all2all = $row_fetch_allFP['LastName'];
$FullName_all2all = $fnameFP_all2all." ".$lnameFP_all2all;
?>
<tr>
<td width="45" bgcolor="#33CCFF"><?=$i?></td>
<td width="70" bgcolor="#33CCFF"><?=$row_fetch_allFP['PersonType']?></td>
<td width="73" bgcolor="#33CCFF"><?echo $FullName_all2all;?></td>
<td width="73" bgcolor="#33CCFF"><?=$row_fetch_allFP['UserName']?></td>
<td width="78" bgcolor="#33CCFF"><?=$row_fetch_allFP['PersonMobile']?></td>
<td width="72" bgcolor="#33CCFF"><?=$SL_all?></td>
<td width="56" bgcolor="#FFFFFF"><a href = 'EditPerson.php'>Edit</a></td>
<td width="138" bgcolor="#FFFFFF"><a href = 'DeletePerson.php'>Delete</a></td>
</tr>
<? $i++; }
}else
{
die("No Record");
}?>
</table>
</div>
<table id = "PTStudentFPR" style = "display:none">
<tr>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Person Type</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Full Name </span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">UserName</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Registration#</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Department</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Programm</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Semester</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Batch</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">CGPA</span></div></td>
<td bgcolor="#3333CC"><div align="center"><span class="style1">Status</span></div></td>
<td bgcolor="#FFFFFF"><div align="center">Edit</div></td>
<td bgcolor="#FFFFFF"><div align="center">Delete</div></td>
</tr>
</table>
</form>
</body>
</html>
Re: How to assign a textbox value to PHP variable??
Posted: Fri Oct 30, 2009 2:17 pm
by juniorjel
Wt shud I do now