Pls Help on TextBox keypress and .live and ONchange!!

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Mon Oct 01, 2012 2:46 pm

You can also just set maxlength on the input, and then truncate the value before you use it....

with this example you can see how even though i've given the field a default value longer than the 3 character maxlength, it ignores the excess if you don't change it, and won't let you re-enter a 4th character if you edit the text box.

Code: Select all

	if(! isset($_POST['submit'])) { //not responding to submit ?>
<form action="trystuff.php" method="post" name="example">
	<input type="text" name="foo" maxlength=3 value="bart"/>
	<input type="submit" name="submit" value="checkit">
	} else { //handle submitted data:
	echo 'foo:'.substr($_POST['foo'],0,3);

Post Reply