473,405 Members | 2,310 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,405 software developers and data experts.

Passing a Smarty array to javascript Function

33
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_PAGES." ";
$result = $uk->tep_mysql_query($sql);
while($rec_url = mysql_fetch_row($result)){
$url_names[] = $rec_url[0];
}
$smarty->assign('url_names' , $url_names);

?>

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

{include file=page_head.tpl}
{literal}
<script language="javascript">
var regex_alphanumeric = /^[a-zA-Z0-9\-\_\s]{2,}$/;
function chk_url(url){
//var m = new Array();
if (!regex_alphanumeric.test(document.create_form.pag e_name.value)) {
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_form" method="post" enctype="multipart/form-data">
<table width="100%">
<tr><td><input name="page_name" type="text" class="textbox1" id="page_name" value="{php}echo $_POST['page_name']; {/php}" size="60" maxlength="60"></td></tr>

<tr><td><input type="text" name="page_title" class="textbox1" size="78" value="{php}echo $_POST['page_title']; {/php}" onFocus="return chk_url('{$url_names}')"></td></tr>
</table>
</form>




Thanks in advance
Nov 15 '07 #1
1 3082
Dasty
101 Expert 100+
your html page is looking like this right now:

[HTML]onFocus="return chk_url('http://sample1.com,http://sample2.com,http://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','http://sample2.com','http://sample3.com'])"
[/HTML]
Nov 15 '07 #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...
1
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
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. ...
12
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...
3
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) {...
2
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...
2
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...
2
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 =...
2
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.