Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using javascript variables to execute html code

 
Mkhaya Tini
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, here is my problem. I have a drop down list with two options, A and B. then a button named say, "OK". When A is selected and OK pressed, I need to execute certain html code, and when B is selected some other code. like a if and else statement but the flag is a drop down list (option). Can I do that? How? Please help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know what you mean by "execute HTML code". DO you mean change the HTML somewhere on the page?
 
Tokai Namnai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, if I'm not clear. Let me try again.

Think it this way: I've a button on a page that will refresh the page, but not exactly. When the first time the page loads from a link, it should execute the code that is in "if". When I click on the button, it should execute the code in "else". in other words, the look of the page will be different if its loaded from a url or by clicking on the button. please let me know if that makes sense.
 
Tokai Namnai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
....Or, please answer this question. In a .jsp file where there are java code, and html and javascript codes, can I assign a value to a JAVA variable using JAVASCRIPT code? if yes how?

i know I can say, var x = '<=%java_var%>' to read a variable. but how do i write?
[ November 09, 2005: Message edited by: Tokai Namnai ]
 
Paul Clapham
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Your JSP code (which may include Java scriptlets) is executed on the server. It generates HTML (which may include Javascript), which is then sent to the client -- your browser. The browser displays this HTML, and executes Javascript as necessary.

When you look at it this way, it should be pretty clear that executing Javascript in the browser can not have any effect on the JSP that has already finished generating HTML.

Now, you can't "execute" HTML code because HTML isn't executable. But it is possible to modify the appearance of the existing HTML via Javascript. There is a model of the HTML in the browser called a "DOM" which you can manipulate via Javascript. So you could make visible fields hidden, add new HTML, all sorts of things.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic