doutao5419 2015-02-26 09:50
浏览 70

获取动态创建的输入的值

I have following jquery script which load a form into a div "blankform"

jQuery('#metentry').submit(function(e){
    e.preventDefault(); 
    // getting data from form to variables
    var date = jQuery('#stddate').val();
    var kgsunit = jQuery('#unit').val();
    var kgsshift = jQuery('#shift').val();

    //sending data to script
    jQuery.post("get_blank_form.php", {
        "date": jQuery('#stddate').val(), 
        'unit': kgsunit,
        'shift': kgsshift, 
    }, function(data) {      
        //loading a form to the div blankform
        jQuery('#blankform').html(data);
    });

get_blank_form.php contains following code

<?php
    echo'<form id="shiftentry" name="shiftentry" >';
    echo "Date:<input id=shiftdate value='".$date."'/>"; 
    echo "Unit:<input id=shiftdate value='".$unit."'/>";
    echo "Shift:<input id=shiftdate value='".$shift."'/><br/>";
    echo "<table><tr><th>No</th><th>Ele</th><th>Location</th><th>Dose Rate (mGy/h)</th><th> Tritium (DAC)</th>  <th>Part (DAC)</th> <th>Iodine (DAC)</th><th>   Surface Cont. (Bq/cm2) </th></tr>";

    while($row2 = mysql_fetch_array($result_sec))
    { 
        echo "<tr>";
        echo "<td>".++$rc."</td>";
        echo "<td><input size='5' id='".$row2['elevation']."' value='".$row2['elevation']."' /></td>";
        echo "<td><input id='".$row2['loc_id']."' value='".$row2['location']."' /></td>";
        echo "<td><input size='5' id='dose".$rc."'  value='".$row2['radn_level']."'/></td>";
        echo "<td><input size='5' id='h3".$rc."' value='0' /></td>";
        echo "<td><input size='5' id='part".$rc."' value='0' /></td>";
        echo "<td><input size='5' id='iod".$rc."' value='0' /></td>";
        echo "<td><input size='5' id='cont".$rc."' value='0' /></td>";
        echo "</tr>";
    }

    echo " </table>";
    echo '<div align="center">';
    echo '<input type="submit" id="submit" name="submit" value="Submit" width="30" />';
    echo '</div>';
?>

this will create a form which will have input like id1, id2 ... id25, dose1, dose2 ... dose25 and so on.

I want to read the values of these input boxes. Normal method like var loc1 = $("#id1").val(); is not working since these elements are dynamically created.

Even the submit button clicking even is also not triggered.

the script below do not produce any output.

jQuery('#shiftentry').submit(function(e) {
    e.preventDefault(); 
    alert("Submitted");

Any suggestions please?

  • 写回答

3条回答 默认 最新

  • doushou8730 2015-02-26 09:55
    关注

    Since the Form DOM is dynamically created after Ajax Call, You can use .on ?

    like:

    $(document).on('submit' , '#shiftentry' , function(e) {
     e.preventDefault(); 
     alert("Submitted");
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100