views:

27

answers:

2

I have a input box with the attribute

overflow:hidden;

I have also used javascript to stopped text being entered so that it cant overflow however I would like to be able to remove any overflow if the user manages to insert text into an already full textbox.

Is there anyway in javascript to detect when a texbox has hidden overflow? and remove it

Thanks

A: 

Are you trying to set the max number of characters that can be entered? If so:

<input type="text" maxlength="50" />
etc
A: 

hi,

if you want to activly trim the text in the input box using javascript you can try:

<html>
<head>
<script>
function clip()
{
    var maxLen = 3
    var box = document.getElementsByName('myInput')[0];
    if (box.value.length > maxLen - 1)
    {
        box.value = box.value.substring(0,maxLen - 1);
    }
}
</script>
</head>
<body>
<input name="myInput" onkeypress="clip()" />
</body>
</html>

this code is not pretty but it shows what you can do, every time the text in the text box gets to long the function trims the text(its a little stronger than what you asked but you can tone it down by changing the event to "onblur"). However, what etc suggested should usually work.

dmig