Assign value to html table element attribute with value from scriptlet

naFianna
naFianna used Ask the Experts™
on
Hello

I would like to set the class and id attributes of the <td> element that is being populated in the scriptlet below

columns is a list of column names

This could contain strings such as accountno, name

history is a data bean

<td>
	<%
	methodName = columns.getId();
	out.println(history.getColumnValue(methodName));
	%>
</td>

Open in new window


Best regards and thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Web Programmer/Technician
Commented:
Columns must be more than a list of column names if it has a method (getId). Regardless, all you need to do is include the td in your scriptlet. I don't see any javascript here and since your <% doesn't specify what language you're using, I'll have to assume you're using php.

	<%
	echo '<td class="'.$someclassname.'" id="'.$someidname.'">'."\n";
	methodName = columns.getId();
	out.println(history.getColumnValue(methodName));
	%>
</td>

Open in new window


If you're not using php, the concatenate symbol will probably be a plus (+) instead of a period (.) so you may need to use a different symbol in line two above.

Author

Commented:
Hi sorry i should have said that the scriptlet is inside a jsp page and the scriptlet language is java

I could not see the wood for the trees and then realised that i can use this

<td class="<%=columns.getId()%>" id="<%=columns.getId()%>">

Open in new window


thanks for the pointer, i was able to get to it from your suggestion

Also you are correct columnlist is a list of simpledatabean with an id and value

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial