473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to use smarty {section} within {literal} JavaScript?

I want to populate a dropdown menu like this:

event.php

Expand|Select|Wrap|Line Numbers
  1. $sql="select * from tbl_clientdetails";
  2. $rs=$conn->Execute($sql);
  3. $client=$rs->getrows();
  4. STemplate::assign('client',$client[0]);
event.tpl

Expand|Select|Wrap|Line Numbers
  1. {literal}
  2.     <script language="javascript">
  3.     function searchclient(searchvalue)
  4.     {
  5.         if (searchvalue == 'clients') {    
  6.                   var clients = "<select name='searchfile' class='input'>";    
  7.         {section name=a loop=2}
  8.                clients=clients+"<option value='{$client[a].name}'>{$client[a].name}</option>";
  9.         {/section}
  10.          clients=clients+"</select>";         
  11.          document.getElementById("searchfile").innerHTML = clients;
  12.          } 
  13.         else {
  14.          var clients = "<input name='searchfile' type='text' />";
  15.          document.getElementById("searchfile").innerHTML = clients;
  16.          }
  17.      }
  18.     </script>
  19.     {/literal}

in boby section of event.tpl
Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="eventsearch.php" name="frm2" >
  2. <div align="right">
  3.                   <span id="searchfile">
  4. </span>
  5.  
  6. <select class="input" onChange="searchclient(this.value)" name="searchcriteria">
  7. <option selected="" value="enclosure">Enclosure</option>
  8. <option value="clients">Client</option>
  9. </select> 
  10.  
  11. <input class="button" type="image" src="../images/search1.jpg" name="submit" />
  12. </div>                  
  13. <div align="right"></div>
  14. </form>
Mar 16 '10 #1
1 5108
Atli
5,058 Expert 4TB
Hey.

Everything within {literal} blocks is displayed as-is, including other smarty syntax. (That's kind of the point.)

So to use {section} in your JavaScript, you need to break out of the {literal} block before using it. Keep in mind that the {literal} around the JavaScript block is only there because of the curly-brackets used in the JavaScript syntax. It doesn't really need to cover the entire code, just the parts that would mess up the Smarty rendering.

You could also check out {ldelim},{rdelim}. They may even better suited for this situation than {literal}, come to think about it.
Mar 16 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Richard | last post by:
I need help. I have a smarty based program that I am modifying. I have a smarty template file that consists of smarty and HTML. I need to integrate some PHP database calls into it. My problem...
5
by: gumshoo3 | last post by:
Hello, These two seem about equal, however I'm leaning towards Flexy. Here's my reasoning below, anything missing? (I've searched but can't find much discussion of smarty vs flexy out...
5
by: glin | last post by:
Hi there, does anyone know how to use smarty to generate a selection list without PHP assigning a array? eg. a list for selection minutes, but without php to assign a 1~60 array into smarty. ...
1
by: cshih16 | last post by:
Can we contain Javascript and CSS codings in .tpl? My tpl file contains Javascript and CSS, but I got syntax error: unrecognized tag Anyway to make it work? because really need those...
7
by: Man-wai Chang | last post by:
1. How could concatenate two values into a string in the template? {section name=j start=0 loop=10 step=1} {section name=k start=0 loop=10 step=1} {assign var=xx...
2
by: Man-wai Chang | last post by:
I meant something like: {section name=j start=0 loop=10 step=1} {php} $xx={$smarty.section.j.index}; echo $xx; {/php} {/section} -- iTech Consulting Services Limited Expert of ePOS...
1
by: sksksk | last post by:
I want to achieve the following process in the smarty for $item one i should be able to get the value using loop.index, but without any luck. any help is appreciated. <?php for ($i = 1; $i...
1
by: RuthC | last post by:
I am trying to pass a smarty array to a javascript function what is he easiest way to pass the values? I tried these code but not working. Please help me where i am wrong. <?php $url_names =...
1
by: ajaymohank | last post by:
hello friends.......... i am new to smarty. can anyone please tell me how to get the value from a dynamically generated checkbox using smarty. this is the code i used... here i am generating 10...
3
dlite922
by: dlite922 | last post by:
Hey guys, For the love of all things holy I can't figure out how to add two numbers together in smarty. I've checked the manual, there's no main section, if it's in there, it's probably lost...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.