954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Clearing the input box

i throw a string value from the database in an input box...when i click update button, i need to clear the textbox after clicking update button..how?thanks a lot...

lloydsbackyard
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 
<form onsubmit='document.getElementById("textbox").value="";'>
<!-- or -->
<input type='submit' onclick='document.getElementById("textbox").value="";'>


or any other combination of form/input & onanything

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

Use some javascript?

// Make sure input as an ID
// e.g.
// put this in Javascript in for when the user has submitted the form

public-image
Junior Poster in Training
76 posts since Oct 2010
Reputation Points: 10
Solved Threads: 11
 

post your code here.. It'll be more helpful to solve your problem

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 

i tried some of the codes above but i cant get it still...the purpose is to update the record...after clicking update the value of the "uname" textbox will be deleted...the values was taken from the datatabase....

below is my code..

<?php
$server = 'localhost';
$user = 'root';
$password = '';
$database = 'studentaccount';
$con = mysql_connect ($server,$user,$password);
$db = mysql_select_db($database);
if (!$db || !$con)
{
die ('SERVER DOWN BE BACK LATER');
}
else
{
$user_id=$_GET['user_id'];
$query = "SELECT * FROM users WHERE user_id=$user_id";
$result = mysql_query($query);
$records = mysql_fetch_array($result);
//$cur_prev = $records ['previledge'];
//echo $user_id;


if (isset($_POST['update']))
{
$uname = strtoupper($_POST ['uname']);
$prev = strtoupper($_POST ['prev']);
$user = md5($_POST ['user']);
$pass = md5($_POST ['pass']);
$date = date("Y-m-d");
$repeatpass = md5($_POST ['repeatpass']);
// echo "$uname/$prev/$pass/$date/$repeatpass";
$user_box = $_POST ['user'];
$pass_box = $_POST ['pass'];
$repeat_box = ($_POST ['repeatpass']);

$query = "UPDATE users
SET name='$uname',
previledge ='$prev',
password = '$pass',
date = '$date'
WHERE user_id = '$user_id';";

if (($user_box)=='' || ($pass_box)=='' || ($repeat_box)=='')
{
echo "ALL FIELDS ARE REQUIRED!";
}
else if(($pass)!= ($repeatpass))
{
echo "PASSWORD MISMATCH";
}
else
{
$result = mysql_query($query);
if ($result)
{
echo "SUCCESSFULLY SAVED!";
}
else
{

echo "SAVE FAILED";
}
}
}
if (isset($_POST['delete']))
{


$query = "DELETE FROM users
WHERE user_id = '$user_id'";
$result = mysql_query($query);


if ($result)
{
echo "Successfully Deleted!";
}
else
{
echo "Delete Failed!";
}

}
}
?>


Name:

Previledge:

<?php
$query = "SELECT * FROM previledges";
$result = mysql_query($query);
echo "";
while($records = mysql_fetch_array($result))
{
echo "{$records ['prev_desc']}";
}
echo "";
?>

Username

Password

Repeat Password




lloydsbackyard
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Try this, there is probably an easier way to just attach a function and onclick to your submit but try that :)

<?php
$server = 'localhost';
$user = 'root';
$password = '';
$database = 'studentaccount';
$con = mysql_connect ($server,$user,$password);
$db = mysql_select_db($database);
if (!$db || !$con)
{
die ('<h3>SERVER DOWN BE BACK LATER</h3>');
}
else
{
$user_id=$_GET['user_id'];
$query = "SELECT * FROM users WHERE user_id=$user_id";
$result = mysql_query($query);
$records = mysql_fetch_array($result);
//$cur_prev = $records ['previledge'];
//echo $user_id;


if (isset($_POST['update']))
{
?>
<script type="text/javascript">
var input = document.getElementById('user');
input.value="";
</script>
<?
$uname = strtoupper($_POST ['uname']);
$prev = strtoupper($_POST ['prev']);
$user = md5($_POST ['user']);
$pass = md5($_POST ['pass']);
$date = date("Y-m-d");
$repeatpass = md5($_POST ['repeatpass']);
// echo "$uname/$prev/$pass/$date/$repeatpass";
$user_box = $_POST ['user'];
$pass_box = $_POST ['pass'];
$repeat_box = ($_POST ['repeatpass']);

$query = "UPDATE users 
SET name='$uname',
previledge ='$prev',
password = '$pass',
date = '$date'
WHERE user_id = '$user_id';";

if (($user_box)=='' || ($pass_box)=='' || ($repeat_box)=='')
{
echo "ALL FIELDS ARE REQUIRED!";
}
else if(($pass)!= ($repeatpass))
{
echo "PASSWORD MISMATCH";
} 
else 
{ 
$result = mysql_query($query);
if ($result)
{
echo "SUCCESSFULLY SAVED!";
}
else
{

echo "SAVE FAILED";
} 
}
} 
if (isset($_POST['delete']))
{


$query = "DELETE FROM users
WHERE user_id = '$user_id'";
$result = mysql_query($query);


if ($result)
{
echo "Successfully Deleted!";
}
else
{
echo "Delete Failed!";
}

}
}
?>



<form method="POST" action="" >
<table align="center">
<tr>
<td>Name:</td>
<td><input type="text" name="uname" value="<?php echo$records['name'];?>"></td>
</tr>
<tr>
<td>Previledge:</td>
<td>
<?php
$query = "SELECT * FROM previledges";
$result = mysql_query($query);
echo "<select name='prev'>";
while($records = mysql_fetch_array($result))
{
echo "<option>{$records ['prev_desc']}</option>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="user" ></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td>Repeat Password</td>
<td><input type="password" name="repeatpass"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="update" value="Update" ><input type="submit" name="delete" value="Delete"></td>

</tr>
</table>

</form>
public-image
Junior Poster in Training
76 posts since Oct 2010
Reputation Points: 10
Solved Threads: 11
 

<td><input type="text" name="uname" value="<?php if(!$_post){echo $records['name'];} ?>"></td>

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

problem solved! thanks a lot...:) More power..God Bless!

lloydsbackyard
Light Poster
34 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: