473,788 Members | 2,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing a Smarty array to javascript Function

33 New Member
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 = array();
$sql = "SELECT `page_url` FROM ".TABLE_USER_PA GES." ";
$result = $uk->tep_mysql_quer y($sql);
while($rec_url = mysql_fetch_row ($result)){
$url_names[] = $rec_url[0];
}
$smarty->assign('url_na mes' , $url_names);

?>

Template file
--------------

{include file=page_head. tpl}
{literal}
<script language="javas cript">
var regex_alphanume ric = /^[a-zA-Z0-9\-\_\s]{2,}$/;
function chk_url(url){
//var m = new Array();
if (!regex_alphanu meric.test(docu ment.create_for m.page_name.val ue)) {
alert("Page Name seems to be invalid, please check it");
document.create _form.page_name .value='';
document.create _form.page_name .focus(); return false;
}else{
for(var i=0; i<url.length;i+ +){
if(url[i] == document.create _form.dispname. value) {
alert("Page Name already exist, please try another");
document.create _form.page_name .value='';
document.create _form.page_name .focus(); return false;
}
}
}

}
</script>
{/literal}


<form name="create_fo rm" method="post" enctype="multip art/form-data">
<table width="100%">
<tr><td><inpu t name="page_name " type="text" class="textbox1 " id="page_name" value="{php}ech o $_POST['page_name']; {/php}" size="60" maxlength="60"> </td></tr>

<tr><td><inpu t type="text" name="page_titl e" class="textbox1 " size="78" value="{php}ech o $_POST['page_title']; {/php}" onFocus="return chk_url('{$url_ names}')"></td></tr>
</table>
</form>




Thanks in advance
Nov 15 '07 #1
1 3115
Dasty
101 Recognized Expert New Member
your html page is looking like this right now:

[HTML]onFocus="return chk_url('http://sample1.com,htt p://sample2.com,htt p://sample3.com')"
[/HTML]

Right? (look at the page source code to see) It is not converted into array by js. (as you are expecting in the function), you have to adjust your php code to generate output like this:

[HTML]onFocus="return chk_url(['http://sample1.com','h ttp://sample2.com','h ttp://sample3.com'])"
[/HTML]
Nov 15 '07 #2

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

Similar topics

1
2314
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 is I cannot figure out how to pass value between smarty and PHP. Going from php to smarty I've tried this: {php} $smarty = new Smarty; $smarty->assign("x", 100);
1
2308
by: Jim Red | last post by:
Hello I have a Smarty(.php.net) Question. I want to create a Navigation with a Smarty Template. How can I display an Array recursively? Do I have to write a Plugin?
5
6969
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. Thanks in advance.
12
6559
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
3
14952
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
4959
by: Freebird | last post by:
Hello you all, =] I've a smarty var, like this: {$var} that is equal to: ttttttttttttt|zzzzzzzzzzzz It can be any size, the important is that they are separated by the '|' How do I 'explode' that into an array or 2 variables in the smarty template
2
3232
by: recordlovelife | last post by:
So I am trying to display a title, date, and content of a wordpress blog. Word press provides nice drop in functions to get the job done with simple names like "the_title", and the "the_content" But on the homepage of a site, i wanted to truncate the content to like the first 75 characters and then put "..." (a perfect use of the smarty "truncate" modifier) and then give the visitor a link to read the whole article. But since "the_content" is a...
2
8068
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 iam wrong. <?php $url_names = array(); $sql = "SELECT `page_url` FROM ".TABLE_USER_PAGES." "; $result = $uk->tep_mysql_query($sql); while($rec_url = mysql_fetch_row($result)){
2
2110
dlite922
by: dlite922 | last post by:
difficult to explain, easier to show: Here's what my data looks like on the PHP side: Array ( => Array ( => 20003001 => ABC RESTAURANT
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10370
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.