ID attributes in Smarty design templates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

ID attributes in Smarty design templates

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

If you're name is unique, wouldn't you be able to retrieve it using document.getElementsByName('Smarty-Name') [0] ?
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post 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.
Post Reply