Advanced Search

Results 1 to 3 of 3

Thread: submit form with javascript like a form does

  1. #1
    Join Date
    May 2007
    Posts
    31
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default submit form with javascript like a form does

    i have a form that contains text, html, and carriage returns in a textarea. when i try to submit this form using javascript (using ajax) it won't submit properly because the html and carriage returns mess up the js variables. for example....

    function submitForm() {
    var t = document.getElementById('myText').value;

    ... [ajax content here].....

    }

    and in the body....

    <textarea id="myText">This is the text I want sent via javascript.

    But things like the carriage returns and links like this <a href="http://www.whatever.com">link</a> are messing things up.</textarea>

    however, if i create a form tag, and submit the form the old fashioned way... it works just fine.

    how can i submit a form using javascript in the same manner the form tag does?

    oh yea, my form tag and ajax are using the post method.

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Well, there is an easy to use and learn tutorial here: http://www.w3schools.com/ajax/default.asp This will make everything easy for you, from using POST or just parsing XML, it WILL do so.

    -magicyte

  3. #3
    Join Date
    May 2007
    Posts
    31
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    thanks, i do love taking tutorials, i will check it out.

    i found the answer to my issue by using this....

    Code:
    var t = escape(document.getElementById('myText').value);
    for (i = 0; i < t.length; i++) {
    	if (t.indexOf("%0D") > -1) {
    		t = t.replace("%0D","<br />");	
    	}
    }
    t = unescape(t);
    now this just works for mac users, but that's fine with me =)

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
  •