rubio
rubio

Reputation: 964

Get textarea contents before submit

I have a textarea by id "compose" and i want to get the data from that textarea before the submit button is pressed. I have another javascript function that will share the information to various other sites based on the user preferences and i need to pass the information in the textarea to that js.

function getVal(){
               alert(document.getElementById("compose").value);

           }

I am not getting any information and im guessing its because the information is stored else where but i dont know where that is stored.

I am using zend with this and i would like to use jQuery but i cannot get jQuery to work properly with zend. It either wrecks other components on the page or does not work at all. Any suggestions?

edit: This is where i am calling getVal(). Its just a link right now as i am trying to get the input into the text area. Then i will insert the found data into my js script.

I attached Zend because the site is made using the zend framework and after a while of stuggling with jquery i didnt want a jquery answer because i would not be able to use it.

<a href="javascript:void(0);" onclick="getVal()">click</a>

edit1 It seems the engine im using has dropped jquery support for the version im using.... Thank you for your answers and help

Upvotes: 0

Views: 1211

Answers (2)

Jasper
Jasper

Reputation: 76003

You can hi-jack the submit event for the form, do your AJAX request, then submit the form normally:

$('form').on('submit', function () {
    $.ajax({
         url  : '<URL>',
         data : { compose : $('#compose').val() }
    });
});

Note that .on() is new in jQuery 1.7 and in this case is the same as .bind().

Docs for .on(): http://api.jquery.com/on

Upvotes: 0

Rodolfo
Rodolfo

Reputation: 4183

since you tagged this as jquery I assume you use it. In that case, the simplest way would be ...

$("#compose").val()

Oh, never mind, I read now that you can't make jquery work? In that case, did you read this post? Best way to start using jQuery in a Zend Framework 1.9 application?

Upvotes: 3

Related Questions