PDA

View Full Version : submit form with javascript like a form does



ahs10
08-29-2008, 09:38 PM
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.

magicyte
09-02-2008, 01:44 AM
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

ahs10
09-02-2008, 07:30 PM
thanks, i do love taking tutorials, i will check it out.

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



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 =)