【发布时间】:2012-12-11 00:59:43
【问题描述】:
我正在使用 JSF,我有一个 h:inputText 文本框,
<h:form>
Please enter your username:
<h:inputText value="#{user.id}"/><br/><br/>
我希望当用户按下提交按钮时,
<h:commandButton value="Submit" action="upload/uploadText"/>
检查输入文本框中是否输入了一个值并且长度超过6个字符
我该怎么做?
我尝试过的代码:
<script type="text/javascript">
function required(){
if (document.getElementById("Username").value.length == 0)
{
alert("message");
return false;
}
return true;
}
</script>
有了这个:
<h:body>
<h:form onsubmit="return required();">
Please enter your username:
<h:inputText id="Username" value="#{user.id}">
</h:inputText><br></br><br></br>
To print a piece of text, please press the submit button below to upload the text:<br/><br/>
<h:commandButton type="submit" value="Submit" action="upload/uploadText"/>
</h:form>
</h:body>
我仍然无法让脚本运行
【问题讨论】:
-
第一步:你读过 JavaScript 验证吗? What have you tried?
-
我已经阅读了有关 js 验证的信息,我只是不确定它是如何检查输入文本框的,在我尝试过的代码上方发布代码
-
这样稍微好点。你怎么打电话给
required? -
我还没有调用它,'onsubmit="required()">' 但我不确定该放在哪里
-
现在有你真正的问题!
标签: javascript jsf