文本框的值打印为未定义

时间:2013-12-07 06:32:05

标签: javascript php jquery html

您好我正在编写代码来获取文本框的值。虽然所有其他值打印完全警报(FormID)打印为未定义。在这里,我已经清楚地评论了我得到了什么。请有人帮助我表明我所犯的错误。

<html>
<title></title>
<head>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script></head>
    <script src="UserTypeSubmit.js"></script></head>
<script>
$(document).ready(function(){

$(".FormEdit").click(function(){

var B=$(this).attr('id');// Ex: Getting ID as FormEdit1 if click on first Edit link
var ReplacesVal=B.replace("FormEdit","");//Prints Value as 1 a I I need.
alert("FormIDInput"+ReplacesVal);//Alert : FormIDInput1
var FormID=$("#FormIDInput"+ReplacesVal).val();
alert(FormID);// Alert: Undefine. Im expecting the value 1 to be in the alert as $("#FormIDInput"+ReplacesVal).val() is equal to 1. and it prints well in the text box.
});
return false;
});
</script>
</head>
<body>

    <div class="User" style="color:#0B173B">Forms_Available_to_Collect_Pubic_Health_Information </div>
<br><br>

        <?php
        include 'connectionPHP.php';

        $result=mysqli_query($con,"SELECT * FROM Form");
    echo "<table border='1' id='DisplayFormDetailss'>
    <tr style='background-color:#D0A9F5;' height='40px;'>
    <th width='100px;'>Form ID</th>
    <th width='420px;'>Form Name</th>
    <th width='100px;'>Inactivate</th>
    <th width='70px;'>Edit</th>
    <th width='70px;'>Delete</th>
    <th width='70px;'>Save</th>

    </tr>";

    $i=1;
        while($row = mysqli_fetch_array($result))
        {   

        $w=$row['Form_ID'];
        $v=$row['Form_Name'];

        echo "<tr height='25px;'>";
        echo "<input id='FormIDInput ".$i."' value='$w' ></input>";
        //Prints 1,2,3,4,5,6 as the values of input boxes perfectly.

        echo "<td name='FormID[]' class='FormID'  align='center' value='$w'>$w</td>";
        echo "<td name='FormName[]' id='FormName".$i."' align='left'>$row[Form_Name]</td>";
        echo "<td name='FormInactive[]' id='FormInactive".$i."' align='center'><input type='checkbox'></input></td>";
        echo "<td class='FormEdit' id='FormEdit".$i."' align='center'><a href='' align=left>Edit</a></td>";
        echo "<td name='FormDelete[]' id='FormDelete".$i."' align='center'><a href='' align=left>Delete</td>";
        echo "<td name='FormSave[]' id='FormSave".$i."' align='center'><a href='' align=left>Save</td>";

        echo "</tr>";
        $i++;
        }

        echo "</table>";


        ?>

</body> 
</html>

3 个答案:

答案 0 :(得分:3)

在PHP代码中,输入框中有一个空格:

 echo "<input id='FormIDInput ".$i."' value='$w' ></input>";

尝试用

替换它
 echo "<input id='FormIDInput".$i."' value='$w' ></input>";

答案 1 :(得分:2)

输入类型中的

缺失类型=&#39; text&#39; &安培;空间问题:

echo "<input type='text' id='FormIDInput".$i."' value='$w' ></input>";

答案 2 :(得分:1)

您需要使用id='FormIDInput".$i."'代替id='FormIDInput ".$i."'。 您可以使用FormID[]

输入的FormIDInput输入文本

尝试使用,

 echo "<td name='FormID[]' id='FormIDInput".$i."'  class='FormID'  align='center' value='$w'>$w</td>";

而不是

 echo "<input id='FormIDInput ".$i."' value='$w' ></input>";
 //Prints 1,2,3,4,5,6 as the values of input boxes perfectly.

 echo "<td name='FormID[]' class='FormID'  align='center' value='$w'>$w</td>";