-2

Is it possible that we can alter the field attribute such as the class="required" or the set is hidden in the HTML using JAVA code?

3
  • 1
    maybe... what have you tried? Commented May 27, 2013 at 8:04
  • Please do not hesitate to post the codes you have tried. Commented May 27, 2013 at 8:05
  • actually i dont have any idea at all how to do it. because i never alter HTML using from JAVA code. Commented May 27, 2013 at 8:16

2 Answers 2

2

Is it possible? YES it is.

Is it JAVA? No, it isn't.

It is Javascript!

Just access your element through the DOM and change the className property.

Example:

document.getElementById('idOfTheElementToChangeClass').className += "required"; //I use += because otherwise it would override all the other classes(if set)
10
  • which mean i cant alter it from a Java file? Commented May 27, 2013 at 8:17
  • If you want to do it client-side then no, you can't Commented May 27, 2013 at 8:18
  • actually what i gonna do is to alter several JSP page. So, i think it is more easier if i can do the logic on a singgle JAVA file. Commented May 27, 2013 at 8:18
  • This code must be added in the HTML file, it doesn't matter if it is .php, .jsp or whatever, is the browser that reads it! Commented May 27, 2013 at 8:19
  • 1
    If I really understood what you want to do(and I'm not sure) then yes, you have Commented May 27, 2013 at 8:25
0

you cannot do it with java if it is a plain HTML page that you are using... you need to use java script in this case...

However, if you are using any dynamic UI technologies like GWT... then you have option to do it using JAVA..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.