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

General discussions related to php

Moderators: macek, egami, gesf

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

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

Post by seandisanti » 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

<?php
	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">
</form>
<?php 
	} else { //handle submitted data:
	echo 'foo:'.substr($_POST['foo'],0,3);
	}
	

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest