Search code examples
postmootoolsinnerhtml

mootools textarea string


I want to send a Request with the content of a textarea but i get only a array instead of the wished string.

<textarea id="putup" name="textarea" cols="70" rows="15">http://www.example.com/?var=2EBR&n=1</textarea>

window.addEvent('domready', function() {
alert($('putup').value);
myRequest = new Request({
method: 'post',
url: 'build2.php',
}).post('var='+$('putup').value+'&uniquebutton='+$('uniquebutton').value);
});

my posts look like this:

Array ( [var] => http://www.example.com/?var=2EBR [n] => 1 [uniquebutton] => aqynnnisqopo )

how to get the real string?


Solution

  • Your code is fine except that your are trying to send a full url in your post without encoding it - which may create a problem if the url also contains parameters - like in your case it's &n=1 that is sending as post param key=>n value=>1 you need to use encodeURIComponent when u send urls and strings that might contains params chars so your param that hold this URL will include the entire URL and won't break it:

    myRequest = new Request({
        method: 'post',
        url: 'build2.php',
    }).post('var='+ window.encodeURIComponent($('putup').value)+'&uniquebutton='+$('uniquebutton').value);
    

    and another little remark - in mootools u can use the get function of element to get any valid property of any element - so you can do $('pupup').get('value') but the classic way $('putup').value is perfectly fine of course.