You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by vimala <th...@gmail.com> on 2008/07/10 20:17:41 UTC

Action form bean values in javascript

Hai all,

I am using struts for web application development. I have a class
clsDateTools within which I define a function public boolean isDate(String
dateToCheck) for validating date values. Here is my jsp page 

<%@ page import="visg.usrBeans.clsDateTools" %>

<html:html>

<script language="JavaScript">

<% clsDateTools datetool = new clsDateTools();%>

function Save(){
	
	................................
	................................

	if(document.someActionForm.txtInspectionDate.value != ""){			
		valuefn = <% =isDate(document.someActionForm.txtInspectionDate.value) %>;
			
		if(valueFn == false){
			alert("Enter valid Complication Date in dd/mm/yyyy");
			return false;
		}
	}
}

</script>


<body onload="onLoadFn()">
    <html:form action="/someAction.do">
	<table align="center" width="100%">
		<tr>
		......
		</tr>

		<tr>
  			<td align="right" width="50%">
            			<p class="normaltextualtheme">Inspection Date</p>
            		</td>
            		<td align="left" width="50%">
   				<script language='javascript'>                
                			var datevalue =
"<%=request.getSession().getAttribute("txtInspectionDate")%>";
                			if(datevalue=="null") {
                				datevalue = "<%=datetool.stringnoDate("/")%>";
                			}
        				if (!document.layers) {
       				document.write("<input readonly='readonly' type=text
name=\"txtInspectionDate\" tabindex=\"2\" value=\""+datevalue+"\" size=10
class=\"readonly\" >");
					document.write("<input type = button name=\"B3\" style=\"width: 20;
height: 20;background-image: url('./images/show-calendar.gif') \" value=\"\"
onclick='popUpCalendar(ttxtInspectionDate, txtInspectionDate,
\"dd/mm/yyyy\");return false;'>");
     			}
    				</script>
 			</td>
  		</tr>
	</table>

    </html:form>
</body>

</html:html>

For the code line valuefn = <%
=isDate(document.someActionForm.txtInspectionDate.value) %>,
it shows an error message 'document is unresolved type'. How can I pass the
action form values as parameters within javascript?

thanks

vimala


-- 
View this message in context: http://www.nabble.com/Action-form-bean-values-in-javascript-tp18388850p18388850.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Action form bean values in javascript

Posted by Dave Newton <ne...@yahoo.com>.
If you're doing validation in JavaScript anyway, why wouldn't you use a JavaScript-based date validation method and avoid the heinous mixing of Java and JavaScript?!

Dave

--- On Thu, 7/10/08, vimala <th...@gmail.com> wrote:
> I am using struts for web application development. I have a
> class
> clsDateTools within which I define a function public
> boolean isDate(String
> dateToCheck) for validating date values. Here is my jsp
> page 
> 
> <%@ page import="visg.usrBeans.clsDateTools"
> %>
> 
> <html:html>
> 
> <script language="JavaScript">
> 
> <% clsDateTools datetool = new clsDateTools();%>
> 
> function Save(){
> 	
> 	................................
> 	................................
> 
> 	if(document.someActionForm.txtInspectionDate.value !=
> ""){			
> 		valuefn = <%
> =isDate(document.someActionForm.txtInspectionDate.value)
> %>;
> 			
> 		if(valueFn == false){
> 			alert("Enter valid Complication Date in
> dd/mm/yyyy");
> 			return false;
> 		}
> 	}
> }
> 
> </script>
> 
> 
> <body onload="onLoadFn()">
>     <html:form action="/someAction.do">
> 	<table align="center"
> width="100%">
> 		<tr>
> 		......
> 		</tr>
> 
> 		<tr>
>   			<td align="right"
> width="50%">
>             			<p
> class="normaltextualtheme">Inspection
> Date</p>
>             		</td>
>             		<td align="left"
> width="50%">
>    				<script language='javascript'>        
>        
>                 			var datevalue =
> "<%=request.getSession().getAttribute("txtInspectionDate")%>";
>                 			if(datevalue=="null") {
>                 				datevalue =
> "<%=datetool.stringnoDate("/")%>";
>                 			}
>         				if (!document.layers) {
>        				document.write("<input
> readonly='readonly' type=text
> name=\"txtInspectionDate\"
> tabindex=\"2\"
> value=\""+datevalue+"\" size=10
> class=\"readonly\" >");
> 					document.write("<input type = button
> name=\"B3\" style=\"width: 20;
> height: 20;background-image:
> url('./images/show-calendar.gif') \"
> value=\"\"
> onclick='popUpCalendar(ttxtInspectionDate,
> txtInspectionDate,
> \"dd/mm/yyyy\");return
> false;'>");
>      			}
>     				</script>
>  			</td>
>   		</tr>
> 	</table>
> 
>     </html:form>
> </body>
> 
> </html:html>
> 
> For the code line valuefn = <%
> =isDate(document.someActionForm.txtInspectionDate.value)
> %>,
> it shows an error message 'document is unresolved
> type'. How can I pass the
> action form values as parameters within javascript?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org