I was trying to print error message in front of a textbox using following code :
我试图使用以下代码在文本框前打印错误消息:
<script type="text/javascript">
<%int n=(Integer)request.getAttribute("n");%>
$(document).ready(function(){
var A=<%=n%>;
$('input[name^=txtDynamic_]').keyup(function () {
if ($(this).val() > A) {
//alert("inside if");
$(this).next().html('Greater than Total shares');
$("#flagvalue").val("invalid");
}
else{
$(this).next().html('');
$("#flagvalue").val("valid");
}
});
if($("#flagvalue").val()=="invalid")
{
$("#submitbutton").prop('disabled', true);
}
else{
$("#submitbutton").prop('disabled', false);
}
});
</script>
and the form is :
形式是:
<FORM METHOD=POST ACTION="stegnographyonshares" enctype="multipart/form-data">
<c:forEach var="i" begin="1" end="${myK}">
Enter The ${i} share number: <input type="textbox" name="txtDynamic_${i}"/><span></span>
<br />
<br>
</br>
</c:forEach>
<br></br>
<INPUT TYPE="file" NAME="file" value="file">
<br></br>
<input type="submit" value="SAVE" id="submitbutton">
<input type="hidden" id="flagvalue"/>
</form>
Whats problem in this ? the script code is not running and though printing the error message but not disabling the button.Please help
这有什么问题吗?脚本代码没有运行,虽然打印错误消息但没有禁用按钮。请帮助
3 个解决方案
#1
0
$(document).ready(function(){
var A = <%=(Integer)request.getAttribute("n")%>
$('input[name^=txtDynamic_]').keyup(function () {
if ($(this).val() > A) {
$(this).next().html('Greater than Total shares');
flag=1;
}
else{
$(this).next().html('');
}
});
});
Demo:
Update:
#2
0
call your code when DOM structure ready, Because the code you have written load prior to the DOM structure generation
在DOM结构准备就绪时调用您的代码,因为您编写的代码在DOM结构生成之前加载
$(document).ready(function(){
//Put your js code here
});
#3
0
try this:
<script>
$(document).ready(function(){
<%int n=(Integer)request.getAttribute("n");%>
var A=<%=n%>;
$('input[name^=txtDynamic_]').keyup(function () {
if ($(this).val() > A) {
$(this).next().html('Greater than Total shares');
flag=1;
}
else{
$(this).next().html('');
}
});
});
</script>
#1
0
$(document).ready(function(){
var A = <%=(Integer)request.getAttribute("n")%>
$('input[name^=txtDynamic_]').keyup(function () {
if ($(this).val() > A) {
$(this).next().html('Greater than Total shares');
flag=1;
}
else{
$(this).next().html('');
}
});
});
Demo:
Update:
#2
0
call your code when DOM structure ready, Because the code you have written load prior to the DOM structure generation
在DOM结构准备就绪时调用您的代码,因为您编写的代码在DOM结构生成之前加载
$(document).ready(function(){
//Put your js code here
});
#3
0
try this:
<script>
$(document).ready(function(){
<%int n=(Integer)request.getAttribute("n");%>
var A=<%=n%>;
$('input[name^=txtDynamic_]').keyup(function () {
if ($(this).val() > A) {
$(this).next().html('Greater than Total shares');
flag=1;
}
else{
$(this).next().html('');
}
});
});
</script>