Why Javascript can't get value in Struts?

I have a button in Struts,when click this button,it will show a value in Struts,like follows:

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="form" %>

<script language="JavaScript">

function a(){

alert(username.value);

}

</script>

<form:form action="/register">

UserName:<form:text property="username"/>

enter password:<form:password property="password1"/>

re-enter password:<form:password property="password2"/>

<form:hidden property="abc" value="3"/>

<form:button property="button" value="Test" onclick="a()"/>

<form:submit value="Register"/>

</form:form>

But when I click Test button,it can't show the value of parameter "username",why? How to show the value of it?

I have a another question,how many attribute of the taglib <form:>? Is there a document for it?

Thanks!

[956 byte] By [EdwardKinga] at [2007-10-2 10:27:37]
# 1

But when I click Test button,it can't show the value of parameter "username",why? How to show the value of it?

Paz>>

<script language="JavaScript">

function a(){

[b]alert(document.forms[0].[/b]username.value);

}

</script>

I have a another question,how many attribute of the taglib <form:>? Is there a document for it?

Paz>>

http://struts.apache.org//struts-doc-1.1/userGuide/struts-html.html

pazhanikanthana at 2007-7-13 2:08:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Sorry Read this as :

But when I click Test button,it can't show the value of parameter "username",why? How to show the value of it?

Paz>>

<script language="JavaScript">

function a(){

alert(document.forms[0].username.value);

}

</script>

pazhanikanthana at 2007-7-13 2:08:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

1) the textfield is part of a form. Normally you would access a form value through FORMNAME.username.value, but you don't define a formname so I think the same can be achieved through forms[0].username.value.

2) for documentation, how about the struts website ?

http://struts.apache.org/

gimbal2a at 2007-7-13 2:08:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
dang, to late :)
gimbal2a at 2007-7-13 2:08:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Insrtead of FormName , I think u should give Bean name to which this form is related to , .......... The name which u use as <html:javascript formName = "YourBeanName" />
nokia6030a at 2007-7-13 2:08:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...