views:

126

answers:

3

Hi,

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"&gt;

<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.

+1  A: 

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

amorfis
It will render if there's a `< script>` instead of `<script>`.
BalusC
True, it's not javascript for a browser. I didn't think about this :) Thanks!
amorfis
Still i am having same problem, please look at the code , let me know what is the problem
+1  A: 

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"&gt;

<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.

Sec
It's a [JSF component library](http://icefaces.org) and according to the [TLD documentation](http://www.icefaces.org/docs/v1_8_2/tld/ice/commandButton.html), it's supported. By the way, it's `onclick`, not `onClick`.
BalusC
A: 

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>
romaintaz