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

?>

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.