gpt4 book ai didi

javascript - 文本框的值打印为 Undefined

转载 作者:行者123 更新时间:2023-11-28 04:57:31 24 4
gpt4 key购买 nike

您好,我正在编写代码来获取文本框的值。尽管所有其他值都打印得很好,但 alert(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>

最佳答案

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

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

尝试将其替换为

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

关于javascript - 文本框的值打印为 Undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20438464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com