Page 1 of 1

ID attributes in Smarty design templates

Posted: Sat Feb 24, 2007 10:02 am
by mjseaden
Hi,

I've tried using the Smarty html_options function to produce a drop-down list box contain data from an array obtained from a database.

This works fine. However, I notice that I can't seem to get the html_options function to include an 'id' tag in the <select> tag it generates, only the name attribute.

This seems a glaring omission, as it would suggest I can't access it using the JavaScript DOM on all browsers using the more reliable getElementById() method.

Am I missing something?

Many thanks

Posted: Sun Feb 25, 2007 10:26 am
by anjanesh
If you're name is unique, wouldn't you be able to retrieve it using document.getElementsByName('Smarty-Name') [0] ?

Posted: Sun Feb 25, 2007 8:14 pm
by Begby
You don't have to have it generate the select tags, you can put in your own select tags with an id. If you omit the 'name' attribute in the smarty tag then only the option list will be generated.

Or you can go into the smarty source and edit the plugins/function.html_options.php file to have it add an id with the same value as the name. Its surprising at how easy it is to edit, or even create from scratch, smarty plugins.