开发者

problem in javascript

problem in javascript validation , how to make call to javascript ?

<!DOCTYPE html>
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component">

<html>
开发者_运维技巧<head>
<script type="text/javascript">
alert('1');
function validate()
{
   alert('inside function');
   var str1;
  // str1 = document.getElementById('name').value;
   //alert(str1);

}    

</script>
</head>
<body>
<ice:panelGrid columns="1" width="760px" styleClass="contentPanel">
<ice:panelGroup>
<ice:outputText value="Name"></ice:outputText>
<ice:inputText value="" id="name" ></ice:inputText>
<ice:commandButton onclick="validate();"></ice:commandButton>

</ice:panelGroup>

</ice:panelGrid>
</body>
</html>

I am not able to access the javascript.Getting error as validate not defined.


Looks like your <script> tag is not closed. Does it render at all?


I know nothing about that icesoft stuff. Are you sure it supports "onclick=" at all?

HTML-wise, it looks ok.

A quick example without the <ice:*> stuff:

<!DOCTYPE html>
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component">

<html>
<head>
<script type="text/javascript">
alert('1');
function validate()
{
   alert('inside function');
   var str1;
}

</script>
</head>
<body>
<form>
<input type=submit onclick="validate();">
</form>

</body>
</html>

works fine for me.


Your code seems correct, except that you have to nest all your inputText and commandButton components in a form:

<body>
    <f:form>
        <ice:panelGrid columns="1" width="760px" styleClass="contentPanel">
            <ice:panelGroup>
                <ice:outputText value="Name"/>
                <ice:inputText value="" id="name"/>
                <ice:commandButton onclick="validate();"/>
            </ice:panelGroup>
        </ice:panelGrid>
    </f:form>
</body>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜