hi please tell me the answer of this question
How to give the variable value to textfield on same page?

Recommended Answers

All 15 Replies

<input type="text" name="username" value="<?php echo $_POST['username']; ?>">

but it wont work when i give the variable value it


means when i store some value in variable and then paas to ur posted code in not working

Can you post your code and explain a lil bit more ?

$user='root';

this is one variable assign value root i just want to show in

<input type="text" name="txtEmpFName" id="txtEmpFName" size="16" width="160" />

when i run the file

<input type="text" name="txtEmpFName" value="<?php echo $user; ?>" id="txtEmpFName" size="16" width="160" />

:) You are welcome!

:) You are welcome!

Hi I'm new to PHP and i'm stuck in this code....
i knw how to do it in javascript but not in PHP
i want to grab the value from a text field and check if tht value exist in an array and if it does then redirect to next page else ask the user to enter a valid number
can u help me plzzz?
thx

Hi I'm new to PHP and i'm stuck in this code....
i knw how to do it in javascript but not in PHP
i want to grab the value from a text field and check if tht value exist in an array and if it does then redirect to next page else ask the user to enter a valid number
can u help me plzzz?
thx

Hi I'm new to PHP and i'm stuck in this code....
i knw how to do it in javascript but not in PHP
i want to grab the value from a text field and check if tht value exist in an array and if it does then redirect to next page else ask the user to enter a valid number
can u help me plzzz?
thx

When the form is submitted, $_POST will have the value of the textbox. Then check if $_POST is in the array using in_array function. http://nl2.php.net/in_array
Then redirect if its in the array.

like write the code for validation in the page which its redirecting to or on the same page where onsubmit it calls a JS function and checks for validation?

Yeah.. something like that.. Simple example.

$id = $_POST['id']; //say the user has entered 10 in the form.
$checkarray = array("10","20","30");
if(in_array($id,$checkarray)){
// redirect.. $id found in the array
} else {
//redirect to error page $id not found in the array
}

ok thanks will try that

ok thanks will try that

<?
session_start();
 $_SESSION['sname'] = 'supnum';  
include ("../../Include_Files/ServerSide/e2a.inc");
include ("../../Include_Files/ServerSide/connect_qisuser.inc");

$query = "select sran8 from custmod.srcmast";

$classRS = odbc_exec($link, $query);
while(odbc_fetch_row($classRS))
{
	$arr[] = odbc_result($classRS,1);
}
 //print_r($arr);
 $sn = $_POST['supnum'];
// echo "sn = ".$sn;

?>
<html>
<head>
<script language="Javascript">
var newWindow;
var newHome;
function check()
{
	
	<? if (in_array($sn,$arr))
	{
	?>
	document.frmSearch.action = ("supp1.php");
	document.frmSearch.submit();
<?
}
else {
?>
alert ("enter a valid number");	
<? }
?>
}
function searchFor1()
{
	if(document.frmSearch.SearchFor.selectedIndex == 1)
	{
		document.frmSearch.action = ("sup.php");
		document.frmSearch.submit();
	}

	if (document.frmSearch.SearchFor.selectedIndex == 3)
	{
		document.frmSearch.action = ("sup_loc.php");
		document.frmSearch.submit();
	}

	if (document.frmSearch.SearchFor.selectedIndex == 4)
	{
		document.frmSearch.action = ("buyer.php");
		document.frmSearch.submit();
	}
	if (document.frmSearch.SearchFor.selectedIndex == 5)
	{
		document.frmSearch.action = ("sup_audit.php");
		document.frmSearch.submit();
	}
	
	if (document.frmSearch.SearchFor.selectedIndex == 6)
	{
		document.frmSearch.action = ("sup_cer.php");
		document.frmSearch.submit();
	}
}
<?

//include ("../../Include_Files/ServerSide/openWindowJ.inc");
//include ("../olrhomeJ.inc");
?>
function help1()
{
	makeNewWindow("help.htm","help","500","400","0","1","1","0","0","1");
}
</script>

<title>Supplier</title>
</head>

<body bgcolor="lightsteelblue" text="black">
<h1><IMG alt="sqa_logo.gif (3854 bytes)" height=73 src="T:/phpbin/images/sqa_logo.gif" width=270 ></h1>
<p align="left">
<input type="button" value="Home" name="Home" tabindex="5" style="font-size: xx-small" onclick="qishome1()">
<input type="button" value="Help?" name="Help" tabindex="6" style="font-size: xx-small" onclick="help1()"></p>

<p align="center"></font><font face="Times New Roman" size="4" color="#000000">
<u>Suppliers Details</u></font><font face="Arial"></p>

<hr size="5">

<p><br>
</p>
<form name="frmSearch" method="POST" action="<?php echo $_SERVER['PHP_SELF']?>">
  <table border="0" width="95%" cellspacing="3">
    <tr>
      <td width="4%" valign="top" align="left">1.</td>
      <td width="30%" valign="top" align="left" nowrap></font><font face="Times New Roman"
        size="3" color="#000000">Select a new<em> Search for</em> option:</font></td>
      <td width="73%" valign="top" align="left">
	  <select name="SearchFor" size="1" onchange="searchFor1()">
          	<option>(select an option)</option>
            <option value="Supplier">Supplier</option>
            <option selected value="Supplier Number">Supplier Number</option>
            <option value="Supplier Location">Supplier Location</option>
            <option value="Buyer">Buyer</option>
            <option value="Audit">Audit Schedule</option>
            <option value="Supplier Certification Level">Supplier Certification Level</option>
          </select></td>
    </tr>
    <tr>
      <td width="4%" valign="top" align="left"><font face="Times New Roman" size="3"
          color="#000000">3.</font></td>
      <td width="30%" valign="top" align="left" nowrap><font face="Times New Roman" size="3"
          color="#000000">Enter a Supplier Number</font></td>
      <td width="73%" valign="top" align="left">
	  <input type="text" name="supnum" size="25" tabindex="1"></td>
    </tr>
    </tr>
    <tr>
      <td width="4%"></td>
      <td width="30%"></td>
      <td width="73%"></td>
    </tr>
    <tr>
      <td width="4%" valign="top" align="left">3.</td>
      <td width="39%" valign="top" align="left"><font face="Times New Roman" size="3"
      color="#000000">Click Search to return a list matching your request: </font></td>
      <td width="57%" valign="bottom" align="left">
	  <input type="submit" value="Search" name="Search" tabindex="2" style="font-size: xx-small" onclick="check()"></td>
    </tr>
    <tr>
      <td width="4%"></td>
      <td width="96%" colspan="2"></td>
    </tr>
  </table>

<?
  odbc_free_result($classRS);
include ("../../Include_Files/ServerSide/close_connection.inc");
//<?php echo $_SERVER['PHP_SELF']
?>
</form>
</body>
</html>

no luck wht could b wrong??

I don't know.. Be specific about your question. What do you mean by no luck ? What is the problem ? My suggestion is, split your script into small parts and debug.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.