Jump to content

get value of textbox without sending a form


JKG

Recommended Posts

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'];

?>

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();
});

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.