By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

Javascript inside struts

P: n/a
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">
<scriptalert('hello'); </script>
</logic:equal>
<logic:equal value="2" name="cifType">
<scriptenableCifType2(); </script>
</logic:equal>
<logic:equal value="3" name="cifType">
<scriptenableCifType3(); </script>
</logic:equal>
</logic:iterate>

Regards
Jean-Francois Michaud

Jan 29 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
VK
On Jan 29, 7:30 pm, "Jean-François Michaud" <come...@comcast.net
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.

Jan 29 '07 #2

P: n/a
"VK" <sc**********@yahoo.comwrote:
>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 <logictags 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
Sl********@bls.gov
http://members.cox.net/slatteryt
Jan 29 '07 #3

P: n/a
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 <headtags). 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">
<scriptalert('hello'); </script>
</logic:equal>
<logic:equal value="2" name="cifType">
<scriptenableCifType2(); </script>
</logic:equal>
<logic:equal value="3" name="cifType">
<scriptenableCifType3(); </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="UpdateKQAVi ewPage.do";
document.body.style.cursor = "wait";
document.ManageKQADocumentForm.submit();
}
}
</script>
</html>

Regards
Jean-Francois Michaud

Jan 29 '07 #4

P: n/a
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.
<scriptenableCifType2(); </script>
This can't work as the form you are trying to script has not yet been
parsed.

<scriptenableCifType3(); </script>
Same here.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 29 '07 #5

P: n/a


On Jan 29, 10:03 am, Martin Honnen <mahotr...@yahoo.dewrote:
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.
<scriptenableCifType2(); </script>This can't work as the form you are trying to script has not yet been
parsed.
<scriptenableCifType3(); </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

Jan 29 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.