JKG Posted August 25, 2011 Share Posted August 25, 2011 hello, i have implemented a jquery function like this: http://jsbin.com/ujuse i need to grab the contents of the textarea to store it in a session, but without sending a form, is this possible?? thanks for looking Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 25, 2011 Share Posted August 25, 2011 look into AJAX Quote Link to comment Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 Thanks MasterACE14, so this is what i have, its not working though... im not too hot with jQuery/AJAX so dummy help would be appreciated. Inital Page: <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script> <script type="text/javascript"> function updateTextArea() { var allVals = []; $('.c_b :checked').each(function() { allVals.push($(this).val()); }); $('#t').val(allVals); var r = new Request.JSON({ 'url': 'script.php', 'method': 'post', 'onComplete': function(success) { alert('AJAX call status: ' + (success ? 'succeeded': 'failed!'); }, 'onFailure': function() { alert('Could not contact server'); }, 'data': 't=' + allVals }).send(); } $(function() { $('.c_b input').click(updateTextArea); updateTextArea(); }); </script> </head> <body> <div class="c_b"> <input type="checkbox" name="contact[]" value="2"> <input type="checkbox" name="contact[]" value="5"> </div> <textarea id="t"></textarea> </body> </html> that works. just not the ajax bit... it doesnt send to the script.php which simply contains <?php session_start(); $_SESSION['contact_ids'] = $_POST['t']; $cont_id = $_SESSION['contact_ids']; ?> Quote Link to comment Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 UPDATE: the above script (with added AJAX) does not work... Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 25, 2011 Share Posted August 25, 2011 is script.php in the same directory as the first page? Quote Link to comment Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 yes . thanks. Quote Link to comment Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 i got that bit of AJAX from here: http://stackoverflow.com/questions/2580229/php-get-value-of-input-box-without-a-form Quote Link to comment Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 ahhh, thats using mootools... Quote Link to comment Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 this is jquery, still doesnt work. it breaks the inital js. function updateTextArea() { var allVals = []; $('.c_b :checked').each(function() { allVals.push($(this).val()); }); $('#t').val(allVals) $.ajax({ type: "POST", url: "script.php", data: "t=".allVals }); $(function() { $('.c_b input').click(updateTextArea); updateTextArea(); }); Quote Link to comment Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 got it to work with this: <script> function updateTextArea() { var allVals = []; $('.c_b :checked').each(function() { allVals.push($(this).val()); }); $('#t').val(allVals); $.post("script.php",{t:allVals}); } $(function() { $('.c_b input').click(updateTextArea); updateTextArea(); }); </script> THANKS! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.