php form to javascript -


i need pass form id javascript, shows same data.

<script> $(document).ready(function() {     $('input[name="submit"]').on('click', function(){         var vauid = $( "input[name='uid']"     ).val(); alert("\n id:  "+vauid);     return false;     });  }); </script>                                                <? include "../includes/config.php"; $sql = "select * table"; $reg = mysql_query($sql); while($row = mysql_fetch_array($reg)){ ?> <form action="" method="post">         <input type="text"   name="uid"     value="<?  echo $row['uid']?>" />         <input type="submit" name="submit" value="show"/> </form>  <? }?> 

part of problem you're inserting numerous forms elements having same names - bad idea names intended unique.

second, when click have reference clicked info:

$(document).ready(function() {     $('input[name="submit"]').on('click', function(e){         e.preventdefault();         var vauid = $(this).prev("input[name='uid']").val();          console.log("id:  "+vauid);     });  }); 

here working demo.

$(this) clicked button previous input's value. i'm using preventdefault() stop button's default action, rather returning false.

in addition should quit using alert() troubleshooting., use console.log() instead.


Comments