Search code examples
javascriptjspstruts-1

How to get the document Id from struts html property


How to get the value of struts property bean in javascript?

Let us say i have the following code in JSP :

<html:checkbox property="age">

The property is defined in bean class :

private boolean age ;

How to get its value in javascript ?

I have done something but it doesn't help.

document.forms['myform'].getElementsByName('age'); //shows error 
TypeError: document.forms.getElementByName is not a function

What should i use in this case ..


Solution

  • Use only

    document.getElementsByName("age");
    

    Edit:

       $(document).ready(function(){
        if(document.getElementsByName("age")[0].checked == true){
                 //do something
              }
        });