Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

How to pass variable of a form using jquey ?

Hello,
I have a form in a file A and I need when clicking on a button to pass some variable to a php file B (commentaireCommande.php)
the php file has to update in db some data (I know how to do)
and it's done I need to know it in file A

what's the correct syntax with jquey  ?   (I'm new with jquery ....)
need ajax ?
thanks for anyhelp.....

<form align="center" method="POST" name="InfoCommande" id="InfoCommande">
<input type="hidden" name="pDevis" value="<?=$pDevis;?>">
<input type="hidden" name="SelectedEd" value="<?= $SelectedEd?>">
      <TEXTAREA  name="InfoCommande" id="InfoCommande" value="" cols="50" rows="2" wrap="physical"><? echo $Int[0];?></TEXTAREA>
      <div id="r" style="display: inline;" >&nbsp; <input type="button" id="action" value="Ok" class='newSmallbouton' <?= $disabled;?>>  </div>
</form>

<script>
 $(function() {
       $("#InfoCommande").on("click", "#action", function(event) {
             $('#r').html('&nbsp;<img src="img/ajax-loader.gif">');
             $.ajax({
                   url: 'commentaire/commentaireCommande.php',
                   data: $('#InfoCommande').serialize(),  // **** added this line ****
                   success: function (response) { //response is value returned from php
//                         $('#r').html(response);
                        alert(response);
                   }
             });
       });
 });
</script>
0
bruno_boccara
Asked:
bruno_boccara
  • 3
  • 3
1 Solution
 
Chris StanyonCommented:
What you've got look like it's heading in the right direction - which part of it isn't working?
0
 
bruno_boccaraAuthor Commented:
I think I'm not using the good way to read the data in file B
I'm using $_post and it doesn't work
How can I retrieve the data pDevis , selectedEd,...
by the way I fix a little bug in the textarea data, it was the same id of the form
I change its id and its name to infoCommandeTexte...
0
 
Chris StanyonCommented:
It's probably because your IDs were the same that you didn't receieve the values. The data is sent to your script using this:

$('#InfoCommande').serialize()

so if your TEXTAREA had the same ID it wouldn't have worked.

Now you've sorted it, you should receive the data in the $_POST array as:

$_POST['pDevis']
$_POST['SelectedEd']
$_POST['infoCommandeTexte']
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
bruno_boccaraAuthor Commented:
it do not work
please note that I do not make a submit of the form
how the the jquery pass the data ?
get , post , ... ?
0
 
Chris StanyonCommented:
Ahh, sorry - I missed that bit - the default request for ajax() is GET. I was thinking of post(). To make the ajax() function use POST you need to add a 'type' argument:

$.ajax({
	url: 'commentaire/commentaireCommande.php',
	type: 'post',
	data: $('#InfoCommande').serialize(),
	success: function (response) {
		alert(response);
	}
});

Open in new window

0
 
bruno_boccaraAuthor Commented:
Many Thanks ....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now