Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Assigning variable value in dropdown list in table

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
snagpal7
Smarty n00b


Joined: 08 Jun 2014
Posts: 2

PostPosted: Sun Jun 08, 2014 9:49 am    Post subject: Assigning variable value in dropdown list in table Reply with quote

I have list of Materials as drop down in each row of table (100 rows).
I want to selectively assign any row selected material.
For example, suppose $materialoptions is assigned an array (1=>'Material 1', 2=>'Material 2',3=>'Material 3'). This is list of dropdown in each row.
I want to assign in php say, In row 20, material selected is 'Material 2'.
Below is my implementation. Not able to assign properly.

HTML/Smarty Code
Code:

<form name='materialsel' id='materialsel' method='POST' action=''>
<table>
{section name=counter start=1 loop=100 step=1}
      <tr>
        <td><SELECT name="materialid_{$smarty.section.counter.index}" id="materialid_{$smarty.section.counter.index}" onchange='return document.forms.materialsel.submit();'><option value='0'>Select Material</option>
   {html_options selected=$material_$smarty.section.counter.index options=$materialoptions}
    </SELECT>
          </td>
     </tr>
{/section}
</table>
</form>

PHP Code
Code:

$template->assign("materialoptions", array (1=>'Material 1', 2=>'Material 2',3=>'Material 3'));
//In row 20, material selected is 'Material 2'
$template->assign("material_20",2); //Not able to do this


Last edited by snagpal7 on Sun Jun 08, 2014 1:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Jun 08, 2014 12:08 pm    Post subject: Reply with quote

Your html_options line should be
Code:
   {html_options selected=$material_{$smarty.section.counter.index} options=$materialoptions}


Besides that it does work at my place.
Back to top
View user's profile Send private message
snagpal7
Smarty n00b


Joined: 08 Jun 2014
Posts: 2

PostPosted: Sun Jun 08, 2014 12:43 pm    Post subject: Reply with quote

Not working on my side. Using Smarty 2
In log, giving error
PHP Fatal error: Smarty error: [in modules/materials.html line 51]: syntax error: $smarty. is an unknown reference (Smarty_Compiler.class.php, line 2126).
Where line 51 is {html_options.......} as above
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP