Jump to content


Photo

Can't get textarea character counter to work with other javascripts!


  • Please log in to reply
3 replies to this topic

#1 daniish

daniish
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 06 October 2006 - 09:49 AM

Hello,

I am writing a form but am having difficulty getting two javascripts to run together. I can get both of them working on their own but not together (I'm using the latest Firefox browser)! The javascripts are:

A wysiwyg text editor
A textarea character counter

You can see my form here:
http://globexposure....blog_form4.html

I tried a second method also (it also doesn't work) which you can see here:
http://globexposure....blog_form2.html

Can anyone tell me why the textarea character counter does not work?


Many thanks

p.s. I posted on a different forum and only got 1 post which said the counter worked but not the WYSIWYG editor (on Safari browser).

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 October 2006 - 01:22 PM

Could you post just the revelant code snippets?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 daniish

daniish
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 08 October 2006 - 07:10 PM

I think it is easiest if i just give you the whole script. May i draw your attention to the 'Label Description:' which is where i am attempting to get both the WYSIWYG editor and character counter to work.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Add Blog </TITLE>

 < script type="text/javascript" >

/***********************************************
* Drop Down Date select script- by JavaScriptKit.com
* This notice MUST stay intact for use
* Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and more
***********************************************/

var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];

function populatedropdown(dayfield, monthfield, yearfield){
var today=new Date()
var dayfield=document.getElementById(dayfield)
var monthfield=document.getElementById(monthfield)
var yearfield=document.getElementById(yearfield)
for (var i=0; i<31; i++)
dayfield.options[i]=new Option(i+1, i+1)
dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day
for (var m=0; m<12; m++)
monthfield.options[m]=new Option(monthtext[m], monthtext[m])
monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month
var thisyear=today.getFullYear()
for (var y=0; y<20; y++){
yearfield.options[y]=new Option(thisyear, thisyear)
thisyear+=1
}
yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
}
</ script >
< SCRIPT LANGUAGE="JavaScript" >

<!-- Begin
   var submitcount=0;
   function checkSubmit() {

      if (submitcount == 0)
      {
      submitcount++;
      document.add_blog.submit();
      }
   }


function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
      {field.value = field.value.substring(0, maxlimit);}
      else
      {countfield.value = maxlimit - field.value.length;}
  }
//  End -->
</ script >
</HEAD>

< script language="JavaScript" type="text/javascript" src="wysiwyg.js" ></ script > 

<BODY>

So you've just visited some place new and exciting...well blog those experiences right here. <br> 
The 'Travel Blog' & 'Associated Link' are not mandatory.<br><br>

< script language="JavaScript" type="text/javascript" src="wysiwyg.js" ></ script > 

<form name=add_blog action="insert.php" method="post">

Title: <br><input type="text" size="79" id="title" method="post" name="title"></input> <br><br>

Date: <br>
<select id="daydropdown"></select> 

<select id="monthdropdown"></select> 
<select id="yeardropdown"></select> <br><br>

Label Description: <br><textarea rows="5" cols="100" id="description" name="description" onKeyDown="textCounter(this.form.description,this.form.remLentext,255);" onKeyUp="textCounter(this.form.description,this.form.remLentext,255);"></textarea> 
< script language="JavaScript1.2">generate_wysiwyg('description');</ script >
<br>Characters remaining: <input type=box readonly name=remLentext size=3 value=255 />
<br><br>

Travel Blog: <br><textarea rows="25" cols="100" id="blog" name="blog"></textarea> 
< script language="JavaScript1.2" >generate_wysiwyg('blog');</ script > 

<br><br>

Latitude: <br><input type="text" size="7" id="lat" name="lat"></input> <br><br>

Longitude: <br><input type="text" size="7" id="lon" name="lon"></input> <br><br>

Associated Link: <br><textarea rows="10" cols="100" id="link" name="link"></textarea> 
< script language="JavaScript1.2" >generate_wysiwyg('link');</ script > 
<br><br>

Marker: <br><input type="text" size="10" id="marker" name="marker"></input> <br><br>


<INPUT TYPE="button" VALUE="Submit" onclick='' name="submit" />
</form>

< script type="text/javascript" >
//populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select)
window.onload=function(){
populatedropdown("daydropdown", "monthdropdown", "yeardropdown")
}
</ script >

</BODY>
</HTML>


Many thanks - i hope you can see a solution!

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 October 2006 - 03:51 PM

Maybe it's easier for you, but I don't have time to wade though all that code.

Are you sure that your textCounter function is being called?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users