Reputation: 81
i want to get text (after submit) and echo it in inputtext, but i face a problem. i want to echo text in inputtext, which is this inputtext outside form, it is fail. but if inputtext inside a form it is success to get text.
1.inputtext inside form -> success
<form id="form1" method="post" action="">
<input type="text" name='search'/>
<?php
$db = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbname,$db);
$sql = mysql_query("SELECT * FROM adminklasifier");
while($row = mysql_fetch_array($sql)) {
$clsfr = $row['klasifier'];
$sql = mysql_query("SELECT * FROM adminklasifier");
echo '<select name="cmake" id="cmake" autofocus width="10" onchange="document.getElementById(\'inputtext\').value=this.options[this.selectedIndex].text">';
echo '<option value="0">-Pilih Domain Klasifikasi-</option>';
while($row = mysql_fetch_array($sql)) {
echo '<option ' . ($clsfr==$row['klasifier']) . ' value="'.$row['klasifier'].'"'.(($_POST['cmake'] == $row['klasifier']) ? 'selected=selected' : NULL).'>'.$row['klasifier'].'</option>';
}
echo '</select>';
}
?>
<input type="submit" id='button' name='button' value="Cari"></input>
<input type="text" name="inputtext" id="inputtext" value="<?php echo $_POST['inputtext'];?>" />
</form>
2.inputtext outside form -> fail
<form id="form1" method="post" action="">
<input type="text" name='search'/>
<?php
$db = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbname,$db);
$sql = mysql_query("SELECT * FROM adminklasifier");
while($row = mysql_fetch_array($sql)) {
$clsfr = $row['klasifier'];
$sql = mysql_query("SELECT * FROM adminklasifier");
echo '<select name="cmake" id="cmake" autofocus width="10" onchange="document.getElementById(\'inputtext\').value=this.options[this.selectedIndex].text">';
echo '<option value="0">-Pilih Domain Klasifikasi-</option>';
while($row = mysql_fetch_array($sql)) {
echo '<option ' . ($clsfr==$row['klasifier']) . ' value="'.$row['klasifier'].'"'.(($_POST['cmake'] == $row['klasifier']) ? 'selected=selected' : NULL).'>'.$row['klasifier'].'</option>';
}
echo '</select>';
}
?>
<input type="submit" id='button' name='button' value="Cari"></input>
</form>
<input type="text" name="inputtext" id="inputtext" value="<?php echo $_POST['inputtext'];?>" />
Can you help to analyze this problem? And i want to get text and echo it in inputtext, but inputtext outside form (like case no.2), will you fix my code? Thanks for helping me.
Upvotes: 0
Views: 158
Reputation: 1
Can you post the generated HTML source code? Your code should show up even though the element is outside of the form. However, it is not the best practice to have it outside the form
Upvotes: 0
Reputation: 94672
<input> fields must exist inside a <form> tag
If you just want to display data outside the form put it in a html tag
of like this.
<p><?php echo $_POST['inputtext'];?></p>
Upvotes: 1