Javascript inside struts

Discussion in 'Javascript' started by Jean-François Michaud, Jan 29, 2007.

  1. Hello,

    I've been trying to figure something out for the past few days and I
    can't seem to pinpoint what I'm doing wrong.

    I've been trying to call javascript from inside a <logic:equal>, but
    it doesn't seem to work like I want.

    I've tried calling an alert('hello'); to test out if my call worked
    correctly, and it does, but when I call my own javascript functions
    that I create in the html/head, they don't seem to get executed. Any
    idea why (except disbaleCif() which I call through onload)?

    Here's a snippet of code:

    <html>
    <head>
    <link REL="stylesheet" HREF="css/bear.css" TYPE="text/
    css">
    <script type="text/javascript">
    function disableCif()
    {

    document.ManageKQADocumentForm.cifType1.disabled="true";

    document.ManageKQADocumentForm.cifType2.disabled="true";

    document.ManageKQADocumentForm.cifType3.disabled="true";
    }

    function enableCifType1()
    {

    document.ManageKQADocumentForm.cifType1.disabled="false";
    }

    function enableCifType2()
    {

    document.ManageKQADocumentForm.cifType2.disabled="false";
    }

    function enableCifType3()
    {

    document.ManageKQADocumentForm.cifType3.disabled="false";
    }
    </script>
    </head>
    <body class="MainBody" onload="javascript:disableCif();">
    <logic:iterate id="cifType"
    property="checkItemFormTypes"
    name="manageKQADocumentTO">
    <logic:equal value="1" name="cifType">
    <script> alert('hello'); </script>
    </logic:equal>
    <logic:equal value="2" name="cifType">
    <script> enableCifType2(); </script>
    </logic:equal>
    <logic:equal value="3" name="cifType">
    <script> enableCifType3(); </script>
    </logic:equal>
    </logic:iterate>

    Regards
    Jean-Francois Michaud
     
    Jean-François Michaud, Jan 29, 2007
    #1
    1. Advertising

  2. Jean-François Michaud

    VK Guest

    On Jan 29, 7:30 pm, "Jean-François Michaud" <>
    wrote:
    > I've tried calling an alert('hello'); to test out if my call worked
    > correctly, and it does, but when I call my own javascript functions
    > that I create in the html/head, they don't seem to get executed. Any
    > idea why (except disbaleCif() which I call through onload)?


    Firefox reports "document.ManageKQADocumentForm has no properties"
    which is correct because neither HTML nor XHTML have element
    ManageKQADocumentForm so UA doesn't have any DOM interface for it.

    I am not clear what markup is that? It is not HTML nor XHTML for sure,
    at the max it is a malformed invalid XML fragment - if served as text/
    html then treated as broken HTML tag soup. In either case
    ManageKQADocumentForm element doesn't appear by some magic.

    It would help to understand what do you mean by "struts" in
    application to (X)HTML then a workable solution could be suggested.
     
    VK, Jan 29, 2007
    #2
    1. Advertising

  3. Jean-François Michaud

    Tim Slattery Guest

    "VK" <> wrote:

    >I am not clear what markup is that? It is not HTML nor XHTML for sure,
    >at the max it is a malformed invalid XML fragment - if served as text/
    >html then treated as broken HTML tag soup. In either case
    >ManageKQADocumentForm element doesn't appear by some magic.


    As he said, it's Struts (http://struts.apache.org), a Java-based web
    application framework. The <logic> tags enable the page to be put
    together conditionally on the server side. The javascript is all
    client side, and I'd say your diagnosis is correct: the element he's
    trying to enabled doesn't exist, at least not in the code he showed
    us. And, even in Struts, that element won't appear by magic.

    --
    Tim Slattery

    http://members.cox.net/slatteryt
     
    Tim Slattery, Jan 29, 2007
    #3
  4. I'm sorry, I should have written down a complete section of code.

    Here goes. ManageKQADocumentForm is a Form I have set up for the
    current jsp page (ManageKQADocumentForm.java). The Form logic work. I
    can transfer data around without problems to and from the Form and a
    Transfer Object is used to communicate with a Database (DAO object).
    My problem is not with the underlying strut logic. It's with the call
    to a javascript function inside a <logic:equal> (the functions are in
    the <head> tags). If I call an "alert('hello world');" inside the
    <logic:equal>, it works, If I call my own function, it doesnt.

    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
    <bean:define id="manageKQADocumentTO" name="ManageKQADocumentTO"></
    bean:define>
    <jsp:include page="/jsp/common/header.jsp" flush="true" />
    <jsp:include page="/jsp/common/menu.jsp" flush="true" />
    <jsp:include page="/jsp/common/errorpage.jsp" flush="true" />

    <html>
    <head>
    <link REL="stylesheet" HREF="css/bear.css" TYPE="text/css">
    <script type="text/javascript">
    function disableCif()
    {
    document.ManageKQADocumentForm.cifType1.disabled="true";
    document.ManageKQADocumentForm.cifType2.disabled="true";
    document.ManageKQADocumentForm.cifType3.disabled="true";
    }

    function enableCifType1()
    {
    document.ManageKQADocumentForm.cifType1.disabled="false";
    }

    function enableCifType2()
    {
    document.ManageKQADocumentForm.cifType2.disabled="false";
    }

    function enableCifType3()
    {
    document.ManageKQADocumentForm.cifType3.disabled="false";
    }
    </script>
    </head>
    <body class="MainBody" onload="javascript:disableCif();">
    <logic:iterate id="cifType" property="checkItemFormTypes"
    name="manageKQADocumentTO">
    <logic:equal value="1" name="cifType">
    <script> alert('hello'); </script>
    </logic:equal>
    <logic:equal value="2" name="cifType">
    <script> enableCifType2(); </script>
    </logic:equal>
    <logic:equal value="3" name="cifType">
    <script> enableCifType3(); </script>
    </logic:equal>
    </logic:iterate>
    <form name="ManageKQADocumentForm">
    <table border="0" width="100%" class="TableBody" cellspacing="0"
    cellpadding="0">
    <tr>
    <td WIDTH="100%" CLASS="PageHeading">KQA Edit Management</td>
    </tr>
    </table>
    <br>
    <table border="0" width="100%" class="TableBody" cellspacing="0"
    cellpadding="0">
    <tr>
    <td>
    <input type="text" name="sbnumber" size="20"/
    >&nbsp;&nbsp;&nbsp;&nbsp;Enter a Service Bulletin

    number.&nbsp;&nbsp;&nbsp;&nbsp;<input type="button"
    name="sbnumbersubmit" value="Submit"
    onclick="javascript:sbnumberCheck()"/>
    </td>
    </tr>
    </table>
    <table border="0" width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <td valign="middle" align="left">
    <input type="radio" name="cifType1" setGroup="group1"
    value="1"/>&nbsp;&nbsp;&nbsp;&nbsp;
    <% int count = 0; %>
    <logic:iterate id="cifTypeLookup"
    property="checkItemFormTypesLookup" name="manageKQADocumentTO">
    <% if(count==0){ %>
    <bean:write name="cifTypeLookup"/>
    <% } count++; %>
    </logic:iterate>
    </td>
    </tr>
    <tr>
    <td valign="middle" align="left">
    <input type="radio" name="cifType2" setGroup="group1"
    value="2"/>&nbsp;&nbsp;&nbsp;&nbsp;
    <% count = 0; %>
    <logic:iterate id="cifTypeLookup"
    property="checkItemFormTypesLookup" name="manageKQADocumentTO">
    <% if(count==1){ %>
    <bean:write name="cifTypeLookup"/>
    <% } count++; %>
    </logic:iterate>
    </td>
    </tr>
    <tr>
    <td valign="middle" align="left">
    <input type="radio" name="cifType3" setGroup="group1"
    value="3"/>&nbsp;&nbsp;&nbsp;&nbsp;
    <% count = 0; %>
    <logic:iterate id="cifTypeLookup"
    property="checkItemFormTypesLookup" name="manageKQADocumentTO">
    <% if(count==2){ %>
    <bean:write name="cifTypeLookup"/>
    <% } count++; %>
    </logic:iterate>
    </td>
    </tr>
    </table>
    </form>
    </body>
    <script language="javascript">
    function sbnumberCheck()
    {
    if(document.ManageKQADocumentForm.sbnumber.value=="")
    {
    alert('Please enter valid Service Bulletin number.');
    }
    else
    {
    document.ManageKQADocumentForm.action="UpdateKQAViewPage.do";
    document.body.style.cursor = "wait";
    document.ManageKQADocumentForm.submit();
    }
    }
    </script>
    </html>

    Regards
    Jean-Francois Michaud
     
    Jean-François Michaud, Jan 29, 2007
    #4
  5. Jean-François Michaud wrote:

    > function disableCif()
    > {
    > document.ManageKQADocumentForm.cifType1.disabled="true";
    > document.ManageKQADocumentForm.cifType2.disabled="true";
    > document.ManageKQADocumentForm.cifType3.disabled="true";


    JavaScript has boolean values true and false while "true" is a string
    and not a boolean value. You should assign true and not "true"
    therefore. The same for the other functions.

    > <body class="MainBody" onload="javascript:disableCif();">


    This should work as it is called after the page has been loaded.



    > <script> enableCifType2(); </script>


    This can't work as the form you are trying to script has not yet been
    parsed.


    > <script> enableCifType3(); </script>


    Same here.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 29, 2007
    #5
  6. On Jan 29, 10:03 am, Martin Honnen <> wrote:
    > Jean-François Michaud wrote:
    > > function disableCif()
    > > {
    > > document.ManageKQADocumentForm.cifType1.disabled="true";
    > > document.ManageKQADocumentForm.cifType2.disabled="true";
    > > document.ManageKQADocumentForm.cifType3.disabled="true";JavaScript has boolean values true and false while "true" is a string

    > and not a boolean value. You should assign true and not "true"
    > therefore. The same for the other functions.
    >
    > > <body class="MainBody" onload="javascript:disableCif();">This should work as it is called after the page has been loaded.

    >
    > > <script> enableCifType2(); </script>This can't work as the form you are trying to script has not yet been

    > parsed.
    >
    > > <script> enableCifType3(); </script>Same here.

    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/


    Ahhhh!! Thats the problem then. The form hasn't been parsed yet!
    Alright, I'll have to find another way of doing this then. Thanks ;-).

    Regards
    Jean-Francois Michaud
     
    Jean-François Michaud, Jan 29, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Katie Wright
    Replies:
    8
    Views:
    4,272
    Andrea Desole
    Jan 7, 2005
  2. sin
    Replies:
    3
    Views:
    732
    Sudsy
    Feb 22, 2004
  3. David Dorward
    Replies:
    1
    Views:
    2,135
    Isofarro
    Jun 28, 2003
  4. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Javascript inside struts

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Jan 29, 2007, in forum: Java
    Replies:
    1
    Views:
    672
    ceasaro
    Jan 29, 2007
  5. spallared
    Replies:
    3
    Views:
    9,382
    david.karr
    May 5, 2007
Loading...

Share This Page