views:

24

answers:

1

hi expert, i need to set value for drop down box when form is load, so i'm able to create normal html element dynamically using javascript as below,

addOption(document.form[0].templateCategory,i,templateCategory[i]);

function addOption(selectbox, text, value) {
  var optn = document.createElement("OPTION");
  optn.text = text;
  optn.value = value;
  selectbox.options.add(optn);
}

but now i need to add for struts element so the value will be selected automatically when form is load, how this can be done,

thanks in advance

A: 

To create select tags and options within, you can combine a variety of Struts tags: select, option, options or optionsCollection.

If you want to mark an option as selected, the value attribute of the <html:select> tag indicates the value to compare with for marking an option selected.

If you want to set the selected option on the onload event, you can still do that using JavaScript. Note though that you apply the JavaScript on the client side, on the HTML that resulted from your Struts server tags.

<html:option> is a server tag and runs on the server. From it results the appropriate <option> tag in the client HTML. You can't interact with <html:option> (or any server tag for that matter) using JavaScript (one runs on server, the other in the client)

dpb