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 Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/ Share on other sites More sharing options...
MasterACE14 Posted August 25, 2011 Share Posted August 25, 2011 look into AJAX Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/#findComment-1261748 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']; ?> Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/#findComment-1261749 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... Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/#findComment-1261750 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? Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/#findComment-1261753 Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 yes . thanks. Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/#findComment-1261755 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 Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/#findComment-1261756 Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 ahhh, thats using mootools... Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/#findComment-1261757 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(); }); Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/#findComment-1261758 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! Link to comment https://forums.phpfreaks.com/topic/245665-get-value-of-textbox-without-sending-a-form/#findComment-1261761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.