Results 1 to 7 of 7

Thread: javascript variable character limit??

  1. #1
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript variable character limit??

    Hey all,

    I have an odd situation, so bear with me.

    I'm using js to populate an email via an html form on our local network. Everything was working fantastically until a user placed an unusually large amt of text into one of the textarea fields. The form just cleared out, but no resulting email was created.

    Just wondering if there is a character limit that is causing this to happen? or a file size issue? or what. If so, what's a good way to break it up into smaller chunks on the fly? I know this is totally not the 'best practices' way of doing this, but you do what you have to I guess.

    Thanks

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    are you sure that it wasn't someone trying to exploit your server via an injection?

    if that was the case then you would need to do a server-side script to validate the content, which you should do anyway... but you could create a limit yourself and just display that. a normal limit for an email is something like 1024 characters, which is a full MB of data. below prints out the first "max_chars" of the string entered.

    Code:
    max_chars = 1024;
    message = document.FORMNAME.FIELDNAME.substr(max_chars);
    As this is Javascript, it is entirely client-side... you should be doing some server-side scripting before you send the email itself.


    Code:
    $message = substr($_REQUEST['message'], 0, 1024);
    where your textarea field has the name "message"

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    There's no problem with PHP or POST, but there might be a limit to the number of characters you can send in an email. It depends on your email server.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes, i'm sure it wasn't an exploit of any kind, as I personally inserted an incredibly large amt of text into the form, and the form failed.

    Also,
    The email will handle the large amt of text, as I've pasted that text into an email, and the email goes through fine. It's definitely a breakdown between the form and the email.

    Thanks for the quick replies.

    Did find this out...

    1500 characters works...1800 does not.
    Last edited by LifeIsBeta; 04-24-2007 at 09:28 PM.

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    then I would say there is a limit put on by your mail server

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    1024 characters is 1KB, not 1MB.

    I've had/sent very long emails... more than that.

    Perhaps a limit.

    Or, are you using GET instead of POST? That may be part of it.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm using post

    Code:
    <form action="" method="post" name="emailForm" id="emailForm" onSubmit="mailForm(document.getElementById('emailForm'));">
    that's on the form

    This is the js

    Code:
    		<script type="text/javascript">
    		<!--
    			function mailForm(form) {
    				if (!form.name == '') {
    					var mailto_string = 'mailto:email@email.com';
    					var mailto_subject = escape('!PROJECT REQUEST! - ' + form.elements['scheduled_item'].value);
    					
    					var mailto_body = escape('**Tracking Number: ' + getTrackingNumber() + "\n\n" + 
    									  '**Desired Date: ' + form.elements['date_due'].value + "\n\n" +
    					                  '**Requestor Name: ' + form.elements['requestor_name'].value + "\n\n" + 
    									  '**Requestor Phone: ' + form.elements['requestor_phone'].value + "\n\n" + 
    									  '**Requestor e-Mail: ' + form.elements['requestor_email'].value + "\n\n" + 
    									  '**Item to Schedule: ' + form.elements['scheduled_item'].value + "\n\n" +
    									  
    									  '**Point of Contact: ' + form.elements['point_of_contact'].value + "\n\n" +
    									  '**Contact Phone: ' + form.elements['contact_phone'].value + "\n\n" +
    									  '**Contact e-Mail: ' + form.elements['contact_email'].value + "\n\n" +
    									  			  
    									  '**Request Details: ' + form.elements['request_details'].value + "\n\n" +
    									  '**Key Benefits: ' + form.elements['key_benefits'].value + "\n");
    									  
    					var mailto_total = mailto_string + '?subject=' + mailto_subject + '&body=' + mailto_body;
    					
    					window.location = mailto_total;
    					return false;
    				} else {
    					return false;
    				}
    			}
    			
    			function getRadioValue(form, field) {
    				var obj = form.elements[field];
    				var checked = 0;
    				
    				for (i = 0; i < obj.length; i++) {
    					if (obj[i].checked == true) {
    						return obj[i].value;
    						checked++;
    					}
    				}
    				
    				if (checked == 0) {
    					return 'ERROR: Unable to retrieve radio button value.';
    				}
    			}
    		//-->
    		</script>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •