Hello Guys,
I'm totally new to this forum and I appreciate to have the ability to discuss on jQuery and to get answers to my questions.
I don't know that much jQuery and I need to modify some code written by someone that knows a bit more about it.
My code involves a bit of PHP, that calls jQuery plugin functions.
My problem follows...
Code on the client page :
- <div>
- <?php
-
- foreach ($joueurs as $joueur) {
- echo '<form roler="form" id="form'.$joueur['id'].'">
- <table class="table">
- <tr>
- <td><input type="text" id="number" value="'.$joueur['number'].'" maxlength="3" size="1"/></td>
- <td><input type="text" id="special" value="'.$joueur['special'].'" size="5"/></td>
- <td><input type="text" id="name" value="'.$joueur['name'].'"/></td>
- <td><input type="checkbox" class="playBox" '.(($joueur['plays'] == 'yes') ? 'checked' : '').' id="'.$joueur['id'].'"/></td>
- <td><button type="submit" id="id_player'.$joueur['id'].'" class="btn btn-warning modifyPlayer">Modify</button></td>
- </tr>
- </table>
- </form>';
- }
- ?>
- </div>
This makes some tables containing informations inside the "
$joueurs" var (from a DataBase).
When I click on a button, I want to get the value of every
<input type="text"> related to the same Form that the pressed button comes from, and the "id" of the button pressed ("
id_playerXX").
The jQuery code involved, that I want to keep as much as possible, follows :
- $('.modifyPlayer').click(function(event) {
- var params = {
- a: 'mp',
- name: $('name').val(),
- numero: $('numero').val(),
- special: $('special').val(),
- id_player: event.currentTarget.id
- };
- $.post('m.php', params, function(response){
- (response == 'ok') ? $("#message").html("Player modified !").fadeIn(2000).fadeOut(2000) : alert('nok');
- });
- event.preventDefault();
- });
I can get the id of the button pressed with "
id_player: event.currentTarget.id". It works for me. But I can't get the value of the textboxes of the SAME form than the button pressed.
After a lot of search on the Internet, I imagine that it should be something like "
name: event.currentTarget.closest('input#name').val()", and I tried a lot of things, but I can't get it to work.
I appreciate any help from you, even if you don't give me answers to my problem.
Thank you in advance,
Kind regards from France !
Baptiste