Jump to content

[SOLVED] Character count restriction in IE


dc_jt

Recommended Posts

Ive posted this in the javascript forum too but there are no members in there so thought I would try here.

 

Ive done the following which works fine in Firefox but doesnt work at all in IE. Anyone know why?

 

Thanks

 


<script language="javascript">
function calculateTextBox(textBoxName, maximum){

	length = document.getElementById(textBoxName).value.length;

	if(length > maximum){
		document.getElementById(textBoxName).value = document.getElementById(textBoxName).value.substring(0, maximum);
	}else{
		remaining = maximum - length;
		document.getElementById('text_limit_'+textBoxName).innerHTML = remaining ;
	}	

}
</script>

			<td><strong>Short Description *</strong></td><td>
				 <textarea class="txtarea400" style="width:100%; height:250;" rows="10" id="description" name="description" onkeyup="calculateTextBox('description', 200);"><?=(isset($_POST['description']))?stripslashes(htmlentities($_POST['description'])):htmlentities($oObj->description)?></textarea>

                  Maximum 200 characters,  <span  id="text_limit_description" >200</span> remaining

			</td>
		</tr>	

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/49966-solved-character-count-restriction-in-ie/
Share on other sites

try this

<script language="javascript">
function calculateTextBox(textBoxName, maximum){

	var str = document.getElementById(textBoxName).value;

	if(str.length > maximum){
		document.getElementById(textBoxName).value = str.substring(0, maximum);
	}else{
		var remaining = maximum - str.length;
		document.getElementById('text_limit_'+textBoxName).innerHTML = remaining ;
	}	

}
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.