我做错了什么,我不知道那是什么。我正在尝试通过id从输入字段中获取文本,并且由于有多个输入字段,因此输入字段处于while循环内。这是我的代码:
if($count22->num_rows>0){
while($row = $count22->fetch_array()){
$mail = $row['UserMail'];
$comment = $row['Comment'];
$comment_id = $row['ID'];
// Reply input field starts
echo " <input type='text' name='reply' id='reply' placeholder='Enter Reply here' min='5' max='100' class='big-input' style='width:40%;margin-left:40px;margin-right:40px;'>";
echo "<button class='btn btn-outline-info' onclick='InsertReply($comment_id)'>Reply</button>";
}
}
单击按钮时,将调用InsertReply函数,其中将检查输入字段是否为空。
InsertReply()函数:
function InsertReply(x) {
alert("Insert Reply Function Called! with comment id : " + x);
//Storing values in variables
var reply = document.getElementById("reply").value; //Error Here,not accepting reply
var mail = document.getElementById("mail").value;
var p_id = document.getElementById("postid").value;
if (reply.length == 0) { //If user has entered nothing
alert("You Entered Nothing!"); //Show message
}
}
问题在于,它仅从第一个输入字段获取文本,即使我输入了文本,对于其余的输入字段,它也会显示警告框“您未输入任何内容”。 让我知道如果您有任何疑问,任何其他解决方案/建议将不胜感激!