wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes javascript function not being called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript function not being called" Watch "javascript function not being called" New topic
Author

javascript function not being called

Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
Hi,

I am using struts 1.1. My jsp is as follows:
<logic:iterate id="Challan" name="Challan">
<tr>
<td >
<bean:define name="Challan" property="products" id="products"></bean:define>
<html:text name = "Challan" property="perbox" size="5" onchange='<%= "javascript:calcBBSeries("+products+");"%>'></html:text>
</td>
</tr>

function calcBBSeries(value)
{
alert("Inside BBSeries");
alert(value);
}

I am not getting any alert. Also the generated code is as follows:
<tr>
<td >
<input type="text" name="perbox" size="5" value="0" onchange="javascript:calcBBSeries(Drawer);">
</td>
</tr>
<tr>
<td >
<input type="text" name="perbox" size="5" value="0" onchange="javascript:calcBBSeries(Units);">
</td>
</tr>

Where am i going wrong?

Please help me out.

Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
you will discover what is going wrong if you open the page using the browser, and then take a look at the generated HTML source ;)


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


It should work on seeing your generated source...Onchange event occurs after iteh textbox loses focus.. check it properly..
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
omar al kababji wrote:you will discover what is going wrong if you open the page using the browser, and then take a look at the generated HTML source ;)


Hi,
This is the generated html source. I cant see anything wrong in this. It is getting the value: onchange="javascript:calcBBSeries(Drawer);", so why it isnt passing it to the function. I am not even getting the first alert. So the function is not being called. I fail to understand what is happening.

Please help me out.

<tr>
<td >
<input type="text" name="perbox" size="5" value="0" onchange="javascript:calcBBSeries(Drawer);">
</td>
</tr>
<tr>
<td >
<input type="text" name="perbox" size="5" value="0" onchange="javascript:calcBBSeries(Units);">
</td>
</tr>

Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
Balu Sadhasivam wrote:
It should work on seeing your generated source...Onchange event occurs after iteh textbox loses focus.. check it properly..


Hi,
I checked it. Its not working. If i replace it with <html:text name = "Challan" property="perbox" size="5" onchange="calcBBSeries('hi');"></html:text>, its working fine.
So the problem lies in 'javascript:calcBBSeries'.

What to do now?

Thanks.
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
simple because you sould enclose the values you pass to the method with single quotations, in other words you should not pass the parameters as

Drawer .... but it should be... 'Drawer'
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
omar al kababji wrote:simple because you sould enclose the values you pass to the method with single quotations, in other words you should not pass the parameters as

Drawer .... but it should be... 'Drawer'

Hi,
Yeah..you are right. I had tried that earlier and it was showing me this error:

org.apache.jasper.JasperException: /pages/viewchallan.jsp(226,88) Attribute value "javascript:calcBBSeries('"+products+"');" is quoted with ' which must be escaped when used within the value

So i had removed the quotes('').



Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
you could write it as follows:

onchange = 'javascript:calcBBSeries(${products});'
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
omar al kababji wrote:you could write it as follows:

onchange = 'javascript:calcBBSeries(${products});'


not working...
this is what it generates:
<td ><input type="text" name="perbox" size="5" value="0" onchange="javascript:calcBBSeries(${products});"></td>

What else should i try?


Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Reason why you output the bolded part inside that?

<%= "javascript:calcBBSeries("+products+");"%>

makes a lot more sense to only do <%= products %>

Also javascript: is a waste in event handlers, loose it.

Eric

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Not related to the actual problem, but using the "javascript:" pseudoprotocol makes no sense. The on* attributes always refer to Javascript by default.

Related to your actual problem: install and run a decent JS debugger. For example Firebug.

Edit: when posting this, the last message of Eric wasn't in view yet. So the first sentence is a bit superfluous.
Edit2: oh now I reread the problem a bit more closely, this isn't a problem with JS at all. Please move this topic to a JSP forum.
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
this is what it generates:
<td ><input type="text" name="perbox" size="5" value="0" onchange="javascript:calcBBSeries(${products});"></td>


it seems that you have EL disabled, however by default it should be enabled, may be you should add the EL needed jars to your class path. by the way try to avoid the use of expressions of type <%= %> in your JSP's, they are old school.
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
omar al kababji wrote:
this is what it generates:
<td ><input type="text" name="perbox" size="5" value="0" onchange="javascript:calcBBSeries(${products});"></td>


it seems that you have EL disabled, however by default it should be enabled, may be you should add the EL needed jars to your class path. by the way try to avoid the use of expressions of type <%= %> in your JSP's, they are old school.


hey, i have all the el related jars in my classpath. But still doesnt seem to work
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
To use EL in template text you need at least a JSP 2.0 compliant container and the web.xml needs at least to be declared as Servlet 2.4 (which implies the use of JSP 2.0). Otherwise you'll need the JSTL's c:out tag instead. Do not use scriptlets in any way. There is in fact no valid business reason to use scriptlets.
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
Bauke Scholtz wrote:To use EL in template text you need at least a JSP 2.0 compliant container and the web.xml needs at least to be declared as Servlet 2.4 (which implies the use of JSP 2.0). Otherwise you'll need the JSTL's c:out tag instead. Do not use scriptlets in any way. There is in fact no valid business reason to use scriptlets.


I tried using c:out tag as follows:

<html:text name = "Challan" property="perbox" size="5"onchange = 'javascript:calcBBSeries(<c:out value="abc" />)></html:text>

But its giving me an error saying attribute <c:out value="abc" /> has no value. Also i want to pass the value of product to the function. How do i do it?

Thanks'>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript function not being called