Jump to content

textarea textfield coutner (on the pageload problem)


arbitter

Recommended Posts

So I have this function from somewhere on the internet, at first it didn't work for a while because I didn't know 'this.form.1' doesn't work but that their needed to be a letter in front of the 1. But that is fixed. Everything works perfectly, the only problem is that the characters don't get counted when the page loads, only when you execute the script (by pressing a button when it's active)

 

Usually you would solve this by doing a body(onload) and load the function, problem is that the function uses 2 parameters and there are multiple textfieldcounters with variable parameters...

 

Here the script anyways:

<script type='text/javascript'>
function textCounter(field, counter) {
var max='140';
if (field.value.length > max)
field.value = field.value.substring(0, max);
else 
counter.value = max - field.value.length;
}
</script>

 

<?php
while($row = mysql_fetch_array($result)){
echo "<form name='form".$row['photoid']."'>";
echo "Afbeelding: " . $row['photoid'] . $row['type'] . "<br />
	<br />
	<textarea onkeydown='textCounter(this.form.a".$row['photoid'].",this.form.counter);' onkeyup='textCounter(this.form.a".$row['photoid'].",this.form.counter);' id='a".$row['photoid']."' name='" . $row['photoid'] . "' >".$row['description']."</textarea><input type='button' onclick=\"update(getElementsByName('".$row['photoid']."')[0].value," . $row['photoid'] . ")\" value='sla op' />";
echo "<div id='".$row['photoid']."'></div>";
echo "<input readonly type='text' name='counter' size='3' maxlength='3' value='140'>";
echo "<hr>";
echo "</form>";
}
?>

 

Thanks in advance!

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.