"Hi,
I need some help with a text box input. This is used in a form to capture results from exams. I need the user to not be able to put in a amount greater than 100, is there a way of doing this?
"Hi,
I need some help with a text box input. This is used in a form to capture results from exams. I need the user to not be able to put in a amount greater than 100, is there a way of doing this?
oh yes, there is a way, here it is
<form>
/*start from your form*/
<input type='text' name='score' maxlength='3' />
</form>
/* Then in PHP, you validate this */
if (isset($_POST['score'] && !empty($_POST['score'])){
if($_POST['score'] > 0 && $_POST['score'] <= 100){
$score = $_POST['score']
}
else{
echo "Value entered is incorrect";
}
else{
echo "Enter your score in the form below";
//and blah blah
}
What this does first of all is to check whether the input is set and its not empty, if passes that, it further checks whether is greater than zero and also less or equal to 100.
Your form will accept only three characters but that is not to say that a user cant post 999 as his score. The condition checks this then.
<html>
<head></head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Enter your mark <input name="score" type="text" size="3">
<input type="submit" name="submit" value="Sub">
</form>
<?php
if (isset($_POST['submit'])) {
$score = $_POST['score'];
if (!empty($score)) {
if ($score > 0 && $score <= 100) {
echo "Validation Process Over";
}
else echo "Type the numeric value";
}
}
?>
</body>
</html>
Guys Thank You very much for your help
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.