• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Clientside validation using javascript in conjunction with STRUTS

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So recently I have begun a project where I need to learn several technologies that I was previously not very familiar with. Javascript and Struts. I had done a little bit with javascript in the past, but never had touched struts before. We are planning on doing some of out form validation on the client side using javascript. I am having trouble getting them to work together. Here is some code. Could someone tell me what I am doing wrong. The webserver I am using is tomcat. Here is some of the code.


< html:form action="/submitCustomerForm" on_blur="return validate()" method="GET" >

PLEASE READ: just so you know, in my code I used the onblur attribute appropriately, the javaranch system kept complaining about when I tried to post, so I put an underscore inbetween on and blur.

The error I get is:
org.apache.jasper.JasperException: /CustomerForm.jsp(28,1) Attribute onblur invalid for tag form according to TLD

Also, it was working perfectly before I added the onblur attribute. Im not sure what I am doing wrong. Any insight would be great. Thanks

By the way. I apologize if I posted in the wrong thread. I posted this question in the javascript thread as well as this one to ensure that I received an adequate response. Thanks again.

Daniel
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you got the message from Bear that we strongly discourage you from cross-posting the same question to multiple threads.

You should have also gotten your answer in the other thread that you should use onsubmit instead of onblur.

Since Bear closed the other thread, I'll leave this one open in case you have follow-up questions or in case someone else wants to comment on it.
 
Daniel Conner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. I apologize about posting the same question in multiple threads. It won't happen again. I fixed the problem and used onsubmit instead. I appreciate the advice. Though, I do have a follow up question. If I was just using javascript with html, I would know how to access the form elements for validation. I could do something like:

if (document.form_name.firstNameTextField.value="")
{
//do something
}

But, I can't seem to figure out how to do the same thing in javascript when I am working with struts. So, how can I go accessing the form elements when using javascript in conjunction with struts? Thanks in advance.

Daniel
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel,

When writing JavaScript code for a Struts JSP, your browser's "view source" function is your best friend. Since JavaScript acts on the rendered plain HTML, rather than the Struts tags, You need to look at how the HTML was rendered by Struts and use that to determine how to write your JavaScript.

Here are a few more guidelines:
  • The name of a form is always the same as the name attribute of the action mapping for the action used by the form in the <html:form> tag. So, if you specified <action name="xyz" path="/myAction" ...> in struts-config.xml, and specified <html:form action="/myAction" >, the name of the form for JavaScript purposes will be "xyz"
  • The name attribute of an input field is always the same as the property attribute in any <html:xxxx> tag
  • You can assign an id attribute to the rendered HTML tag by specifying a styleid attribute in your struts tag

  • [ January 25, 2007: Message edited by: Merrill Higginson ]
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic