0

I want to try to get the value from a checkbox using JSP but so far with not success

  <%!
    // Define global variables
    String state = "off";
%>

      <%!
    public void getState(String state) {
        if(state.equals("on")){
            %> <h1>ON</h1> <%!
        }
  }
  %>


        <!-- Toggle button -->
        <div class="togglebutton">
          <label>
            <input type="checkbox" onclick="<% getState(state); %>">
              <span class="toggle"></span>
                Toggle is off
          </label>
        </div>

The thing with this code is that it print the function without being called! any help will be much appreciated!

shmosel
  • 49,289
  • 6
  • 73
  • 138
shaveax
  • 123
  • 1
  • 1
  • 12

2 Answers2

0

<input TYPE=checkbox name=sports VALUE=Cricket> try this syntax I hope the code work without error

Lamia
  • 1
0

I think because you put a print statement in the if statement, try to follow this style

 <body>
      <%!               
      public int add(int a,int b)           
              {                                     
        return a+b;
              } 
       %>

      <% 
      int k;                
          k=add(5,6);
      %>

      <%=                   
          k                     
      %>

    </body>