PDA

View Full Version : Form field Limiter Help?



Hip_Hip_Array
02-14-2007, 10:45 AM
1) Script Title: Form field Limiter

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex16/limitinput.htm

3) Describe problem:
Hello all,
I have two text areas on my form and I want this script to check both fields. But I can only get it to check one of them.

This is my form before I add the script:-


<h3>What are your main issues?</h3><br>
<form name="all_issues" action="save_issues.php" method="post">
<textarea rows="6" cols="60" name="main_issues"></textarea><br>
<br><hr><br>
<h3>Please enter any further suggestions</h3><br>
<textarea rows="6" cols="60" name="suggest">
</textarea>
<br></center><br>
<input type="submit" value="Save / Update"></form><hr>

I then put the main part of script in the head and edited the part above like so:-


<h3>What are your main issues?</h3><br>
<form name="all_issues" action="save_issues.php" method="post">
<textarea rows="6" cols="60" id="issues" name="main_issues"> </textarea><br>
<script>
displaylimit("","issues",2000)
</script>
<br><hr><br>
<h3>Please enter any further suggestions</h3><br>
<textarea rows="6" cols="60" id="suggestion" name="suggest"></textarea>
<br>
<script>
displaylimit("","suggestion",2000)
</script>
</center><br>
<input type="submit" value="Save / Update"></form><hr>

The top text area display limit works fine, but the second remains static.

What am I doing wrong? I thought using id's would allow the use of two text areas?

Many Thanks

ddadmin
02-14-2007, 12:21 PM
Try switching to entering the form field's name instead of its ID. So in your case:


<h3>What are your main issues?</h3><br>
<form name="all_issues" action="save_issues.php" method="post">
<textarea rows="6" cols="60" id="issues" name="main_issues"> </textarea><br>
<script>
displaylimit("document.all_issues.main_issues","",2000)
</script>
<br><hr><br>
<h3>Please enter any further suggestions</h3><br>
<textarea rows="6" cols="60" id="suggestion" name="suggest"></textarea>
<br>
<script>
displaylimit("document.all_issues.suggest","",2000)
</script>
</center><br>
<input type="submit" value="Save / Update"></form><hr>

This script is rather old and not exactly intuitive. Another script up for a makeover soon. :)

Twey
02-14-2007, 06:59 PM
displaylimit("document.all_issues.suggest","",2000)Don't access forms or elements like that: it's non-standard and can cause confusion if the form or element has a name identical to a property of the document or form objects. Instead, use:
displaylimit("document.forms['all_issues'].elements['suggest']","",2000))You're not wrong about this script needing a makeover... here (http://www.twey.co.uk/includes/FormLimiter.js)'s a candidate. It was written on the spur of the moment, so documentation is still sparse.

ddadmin
02-15-2007, 12:04 PM
Trey:
I don't doubt for a moment your version (http://www.twey.co.uk/includes/FormLimiter.js) is better than the current one. :) When I get to updating this script I'll take a look again at your code, and possibly (with your permission of course) just go with it. I enjoy rewriting old scripts on DD though- it has this cleansing effect hehe.

Twey
02-15-2007, 03:02 PM
Trey:Again? :p
When I get to updating this script I'll take a look again at your code, and possibly (with your permission of course) just go with it.Of course.
I enjoy rewriting old scripts on DD though- it has this cleansing effect hehe.Heh -- there are plenty to go around :p