Forum Moderators: open

Message Too Old, No Replies

adding another close to identical script

         

Simone100

10:35 am on Jan 16, 2007 (gmt 0)

10+ Year Member



Hi I am using this in one of my pages. I need to add another to the same page but just changing the function name didn't help. Can someone help me alter this a bit so I can use it again in the same page, so it doesn't conflict with the first? Thank you very much.

<script type="text/javascript">function CheckSize(form, field) {
if (field ==1) {
Ctrl = form.comments;
y = 300+1;
}
else {
Ctrl = form.longdescription;
y=300;
}
x = Ctrl.value.length;
if (x < y)
SendMsg (Ctrl, "Number of characters is: " + x); else
SendMsg (Ctrl, "Warning! Description Too Long. Number of characters is: " + x);}
function SendMsg (Ctrl, PromptStr) { alert (PromptStr)
;
Ctrl.focus(); return;}
</script>

<textarea rows="2" cols="15" name="comments"></textarea><input value="Count Characters" onclick="CheckSize(this.form,1)" type="button" />

daveVk

3:25 am on Jan 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script type="text/javascript">function CheckSize(Ctrl, y ) { // y is max size
if ( Ctrl.value.length < y)
SendMsg (Ctrl, "Number of characters is: " + x); else
SendMsg (Ctrl, "Warning! Description Too Long. Number of characters is: " + x);}
function SendMsg (Ctrl, PromptStr) { alert (PromptStr)
;
Ctrl.focus(); return;}
</script>

<textarea rows="2" cols="15" name="comments"></textarea><input value="Count Characters" onclick="CheckSize(this.form.comments,301)" type="button" />

<textarea rows="2" cols="15" name="special"></textarea><input value="Count Characters" onclick="CheckSize(this.form.special,400)" type="button" />

Simone100

4:47 am on Jan 18, 2007 (gmt 0)

10+ Year Member



Hey Dave!

Looks like I need a bit of a walk through, I'm doing something wrong. I'm pretty sure you want me to put the number of characters
here...... function CheckSize(Ctrl,300) {
and here?...... if ( Ctrl.value.length <300)
What about in these? Anything go here before the x?
SendMsg (Ctrl, "Number of characters is: " + x); else
SendMsg (Ctrl, "Warning! Description Too Long. Number of characters is: " + x);}

Then this in the body.
(this.form.special,400)
Do I need to change anything?
Thank you very much.

Simone100

5:34 am on Jan 18, 2007 (gmt 0)

10+ Year Member



Don't sweat it Dave, someone sent me the answer in a PM. See you later! S.

daveVk

6:44 am on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My error in script, try

<script type="text/javascript">function CheckSize(Ctrl, y )
if ( Ctrl.value.length < y)
SendMsg (Ctrl, "Number of characters is: " + Ctrl.value.length); else
SendMsg (Ctrl, "Warning! Description Too Long. Number of characters is: " + Ctrl.value.length );}
function SendMsg (Ctrl, PromptStr) { alert (PromptStr)
;
Ctrl.focus(); return;}
</script>

Dont replace anything in this script, you only need one copy of script

Length goes into call to CheckSize, 400 in example below

<textarea rows="2" cols="15" name="special"></textarea><input value="Count Characters" onclick="CheckSize(this.form.special,400)" type="button" />

You can have as many textarea as you like, names must be different for each textarea, replace "special" in both places in example above.