简体   繁体   中英

How to get a input value from dynamic list

I don't know how to get the value, with js always show me the first input value! Thanks in advance!!!

<html>
<head>
</head>
<body>
<?php 
while($i < $forid){
?>
<div id="mydiv">
    <input type="text" id="myid" name="myid" value="<?php echo $arrayid[$i]; ?>">
    <input type="text" id="myname" name="myname" value="<?php echo $arrayname[$i];?>">
    <input type="text" id="myjob"name="myjob" value="<?php echo $arrayjob[$i]; ?>">
    <input type="submit" value="get values" id="getvaluesbutton">
</div>  
<?php
$i++;
}
?>
</body>
</html>

Get array access to elements by class/name in your js script by changing html:

<?php 
while($i < $forid){
?>
<div id="mydiv">
    <input type="text" name="myid[]" class="myid" value="<?php echo $arrayid[$i]; ?>">
    <input type="text" name="myname[]" class="myname" value="<?php echo $arrayname[$i];?>">
    <input type="text" name="myjob[]" class="myjob" value="<?php echo $arrayjob[$i]; ?>">
    <input type="submit" value="get values" id="getvaluesbutton">
</div>  
<?php
$i++;
}
?>

for javascript hints read this question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM