SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Problem with AJAX

    i used get method using AJAX for Forms...but I have a small problem here..


    when I use <textarea> if some one types the message like...
    Code:
    Hello Sir,
    
    
    Thanks...
    I get like
    Code:
    Hello Sir,Thanks....
    Can any one solve me this problem...

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nl2br($text);

  3. #3
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hash View Post
    nl2br($text);
    can u give me with more detailed...

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by yuvasai View Post
    i used get method using AJAX for Forms...but I have a small problem here..


    when I use <textarea> if some one types the message like...
    Code:
    Hello Sir,
    
    
    Thanks...
    I get like
    Code:
    Hello Sir,Thanks....
    Can any one solve me this problem...
    Better go for AJAX Post

    And see escape function in JavaScript.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the code i used
    Code:
     <form name="ReportLink">
    <label class="formFieldQuestion">Name&nbsp;*</label><input type=text name=Name id=Name size='20' value='' autocomplete="off">
    <label class="formFieldQuestion">E-mail&nbsp;*</label><input type=email name=Email id=Email size=20 value="" autocomplete="off" style="background-image:url(../images/email.png); background-repeat: no-repeat;  padding: 2px 2px 2px 25px;">
    <label class="formFieldQuestion">Comments&nbsp;*</label><textarea name=Comments id=Comments rows=5 cols=10></textarea>
    <input type="button" value="Send Broken Link" onclick="ajaxFunction();">
    </form>
    Ajax code
    Code:
    function ajaxFunction(){
    	var ajaxRequest;  
    	
    		try{
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
     
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    	ajaxRequest.onreadystatechange = function(){
    		if(ajaxRequest.readyState == 1){
    			var ajaxDisplay = document.getElementById('ajaxDiv');
    			ajaxDisplay.innerHTML = "Loading...Please Wait.";
    		}
    		if(ajaxRequest.readyState == 4){
    			var ajaxDisplay = document.getElementById('ajaxDiv');
    			ajaxDisplay.innerHTML = ajaxRequest.responseText;
    		}
    	}
    	var Name = document.getElementById('Name').value;
    	var Email = document.getElementById('Email').value;
    	var Comments = document.getElementById('Comments').value;
    	var queryString = "?Name=" + Name + "&Email=" + Email + "&Comments=" + Comments;
    	ajaxRequest.open("GET", "report.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    So what should I do now.....??

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by yuvasai View Post
    So what should I do now.....??
    1. Scroll up to the top of the page
    2. Look at the forum you chose to post a javascript question in

    edit: I see down the bottom there you are posting to a php script. Perhaps share that, but I suspect that nl2br will solve your problem if the php script is providing the output.

  8. #8
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes try nl2br() once in your report.php file once and see if that solves your problem. BTW what do you want that text to be ... stored in db or sent to mail or just print in the webpage/html?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  9. #9
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow

    Quote Originally Posted by rajug View Post
    Yes trynl2br() once in your report.php file once and see if that solves your problem. BTW what do you want that text to be ... stored in db or sent to mail or just print in the webpage/html?
    it's not working..
    mail it...

    for normal posting it works perfectly...but by using Ajax it doesn't works...

    and can any one code for this

    the code for enter key is

    Code:
    &#37;0D%0A
    Last edited by yuvasai; May 31, 2009 at 07:21.

  10. #10
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try the JavaScript function 'escape' what i had said in my first post? See the following example which works pretty well.
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    	<title>AJAX Test</title>
    	<script type="text/javascript" src="JsAjax.js"></script>
    </head>
    <body>
    <form method="post">
    	<textarea name="txt" id="txt" rows="5" cols="40"></textarea><br />
    	<input type="button" name="btnsubmit" value="Submit" onclick="sendGetRequest('mail.php?txt=' + escape(this.form.txt.value), 'showResult', 'showResult');" />
    	<div id="showResult"></div>
    </form>
    </body>
    </html>
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


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
  •