SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Carriage return

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Carriage return

    I have a piece of javascript code within PHP. Its a simple validation script. I want to do a new line feed but if i put in a \n between "form!" and "Please" like "form!\nPlease" it breaks the code.

    Code:
    <script language=\"JavaScript\" type=\"text/javascript\">
    function Validate(){
    
    	var error = 0;
    	var error_message = \"Errors have occured during the process of your form!Please make the following corrections:\";
    
    	var firstname = document.contact.fname.value;
    	var lastname = document.contact.lname.value;
    	var telephone = document.contact.phone.value;
    	var email = document.contact.email.value;
    	
    	if (firstname.length < 2) {
    		error_message = error_message + \"* Your First Name is required.\";
    		error = 1;
    	}
    	if (lastname.length < 2) {
    		error_message = error_message + \"* Your Last Name is required.\";
    		error = 1;
    	}
    	if (telephone.length < 10) {
    		error_message = error_message + \"* Your Telephone Number is required.\";
    		error = 1;
    	}
    	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(contact.email.value)){
    	
    		error_message = error_message + \"* Your E-Mail Address is not valid.\";
    		error = 1;
    
    	
    	   }
    
    	
    	if (error == 1) {
    		alert(error_message);
    		return false;
    	} else {
    		//alert(error);
    		return true;
    	}
    	
    	
    }	
    </script>

  2. #2
    SitePoint Zealot
    Join Date
    Sep 2007
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you show the php too

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2007
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh i see, the javascript breaks cause the newline is printed when the javascript is printed

    just try \\n

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Spot on! Spot on!

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm....another problem....it doesnt work with firefox. Any suggestions?

  6. #6
    SitePoint Zealot
    Join Date
    Sep 2007
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    show all the code


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
  •