Solved

How to pass variable of a form using jquey ?

Posted on 2013-06-27
6
435 Views
Last Modified: 2013-06-28
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
Comment
Question by:bruno_boccara
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39282463
What you've got look like it's heading in the right direction - which part of it isn't working?
0
 

Author Comment

by:bruno_boccara
ID: 39282727
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
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39282767
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bruno_boccara
ID: 39282799
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
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39282848
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
 

Author Closing Comment

by:bruno_boccara
ID: 39283651
Many Thanks ....
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to calculate height of a text using jquery 3 43
ASP sending two datas 2 23
Jquery if else not working ... WHY? 5 26
AngularJS: ng-repeat 25 28
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question