Hi all,

I would like to have a textarea where users can type just a limited amount of characters. I already have the Javascript to control this (excluding the scripts, it looks like:

  <textarea name="short" 
  onKeyDown="limitText(this.form.short,this.form.countdown,1250);" 
  onKeyUp="limitText(this.form.short,this.form.countdown,1250);">
  </textarea><br>
   You have <input readonly type="text" name="countdown" size="4" value="1250">      
  characters left.

I created a component of "markup" type, but I'm not able to feed Webform through it. I tested it also with very basic code in the markup Value area, like this:

 <label for="edit-submitted-test1">Test1: </label>
 <input type="text" name="submitted[test1]" id="edit-submitted-test1" size="60" value="" class="form-text" /> 

but whatever I type in the field is never saved! Webform saves the whole field, empty! I'm sure I'm missing something really stupid, but seems I can solve this by myself :-\

Thanks in advance for any suggestion and bye

Gabriele

CommentFileSizeAuthor
#2 Captured001.png11.68 KBggamba
#2 Captured002.png26.38 KBggamba

Comments

quicksketch’s picture

Markup components each have options for Input format. What's happening here is your markup component is set to use the default "Filtered HTML" input format, which strips out all JavaScript. If you change the input format to "Full HTML", the component will properly print out the script.

ggamba’s picture

StatusFileSize
new26.38 KB
new11.68 KB

Thanks for your reply! Unfortunately it did not cure the problem. It was set on "PHP": I changed it to "Full HTML but nothing changed :-\
I have attached two screenshot just to be safe.

quicksketch’s picture

Oh, I completely misunderstood your question. I thought you were saying that the text you entered into the markup component (the form element) wasn't saving.

Manually typing in HTML into a page will never allow the end user to enter a value that will save. If that were the case, you could just make an HTML page and paste forms into it! There's a lot of additional processing that Webform needs to do, and in order to perform the processing it has to know a lot of information about the field, more than an HTML string can provide.

What you really need is to simply add JS to your form, not making entire form elements in the markup component (however you can use the markup component to add your additional JS).

Drupal includes the jQuery library, which I'd suggest you use instead of doing inline code in the form element itself. You could use the following code to achieve the same effect:

<script type="text/javascript">
$('#edit-submitted-test1').keyup(limitText).keydown(limitText);
</script>

You can learn more about jQuery at http://jquery.com and (my favorite) http://visualjquery.com

ggamba’s picture

Quicksketch, thank you!

With your explanation (and with help from this page: http://www.ajaxray.com/blog/2007/11/09/interactive-character-limit-for-t... :-)
I was able at last to have exactly what I was looking for!

Thanks again a lot and bye

Gabriele

quicksketch’s picture

Title: How to control number of characters in a textarea » JavaScript limit number of characters in a textarea
Status: Active » Fixed

Glad you found what you needed. :)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.