user3044874
user3044874

Reputation: 187

Use Java variable in HTML tag

I'd like to be able to use a java variable as one of the attributes of my HTML tag. For example, I'd like to be able to do this:

<% String questionId = "question" %>
Question: <textarea rows="5" cols="20" name=questionId><%=question %></textarea> 

Where the name attribute would equal "question". The above doesnt work; is there any possible way to do this?

Upvotes: 2

Views: 6302

Answers (2)

Thanga
Thanga

Reputation: 8091

You are not using the variable you set. Means you set questionId and accessing question It has to be fixed as below

<% String questionId = "question" %>
Question: <textarea rows="5" cols="20" name=questionId><%=questionId %></textarea> <br>

Upvotes: 1

piet&#224;
piet&#224;

Reputation: 770

you've forgot the semicolon. try this it must work :

<% String questionId = "question"; %>
Question: <textarea rows="5" cols="20" name=questionId><%=question %> </textarea> <br>

Upvotes: 0

Related Questions