Passing ASP array into javascript function

P

Patrice

HI,

1- I fill an array (arrayName ) of records (news and news titles) from an
ACCESS database.

2- I call a function (loopDatasNews()) to build a table of news titles.

3- I call javascript function as to write a news when a "read more"
hyperlink under a new title is clicked

Here is my problem: An Error occurs each time an apostrophy or a ")" is in a
database record. This means that the javascript function doesn't work each
time an " ' " is encountered in the "Increm" ASP variable .

I tried to use :

Increm= cstr(arrayName(col,n)) but it still doesn't work

Does anyone know how to fix this?

Thank in advance



<%

function loopDatasNews(col,arrayName)

nRowCount = ubound(arrayName, 2)

For n=0 to nRowCount

Increm= ""&arrayName(col,n)&""

response.write("<table
class=""tableNews""><tr><td>"&arrayName(col-1,n)&"</td></tr><tr><td
id='id"&n&"'><a class=""read"" href=""javascript:;""
onclick=""showNews('id"&n&"','"&Increm&"');"">readMore</a></td></tr></table>
<BR>")

Next

End Function

%>



<script language="javascript">

function montre(id, shtml) {

if (document.getElementById) {

document.getElementById(id).style.visibility =
'visible';

} else if (document.all) {

document.all[id].style.visibility = 'visible';

} else if (document.layers) {

document.layers[id].visibility = 'visible';

};

var el = (document.getElementById)?
document.getElementById(id): (document.all)? document.all[id]:
(document.layers)? document.layers[id]: null;

if (!el) return;

if (typeof el.innerHTML!="undefined") {

el.innerHTML = shtml;

} else if (document.layers) {

el.document.write(shtml);ol

el.document.close();

} }

</script>



Patrice Baudin
 
S

swp

use a function like this to change your strings before you process them

function checknullA(xvar, xval)
if (isnull(xval) or xval="") then
checknullA = xvar & "=NULL"
else
checknullA = xvar & "='" & replace(xval, "'", "''") & "'"
end if
end function

hope this helps,
swp
 
D

Dominique

Function clnStr(ByVal str)
Str = replace(str & " ","'","`")
Str = trim(Str)

'Use this condition if this function is only gonna be used for cleaning
data before DB inserts/updates
'Else just go to: "clnStr = Str"
if Str = "" then
clnStr = NULL
else
clnStr = Str
end if
End Function


Always best to clean your data BEFORE you insert it into the database



Patrice said:
HI,

1- I fill an array (arrayName ) of records (news and news titles) from an
ACCESS database.

2- I call a function (loopDatasNews()) to build a table of news titles.

3- I call javascript function as to write a news when a "read more"
hyperlink under a new title is clicked

Here is my problem: An Error occurs each time an apostrophy or a ")" is in a
database record. This means that the javascript function doesn't work each
time an " ' " is encountered in the "Increm" ASP variable .

I tried to use :

Increm= cstr(arrayName(col,n)) but it still doesn't work

Does anyone know how to fix this?

Thank in advance



<%

function loopDatasNews(col,arrayName)

nRowCount = ubound(arrayName, 2)

For n=0 to nRowCount

Increm= ""&arrayName(col,n)&""

response.write("<table
class=""tableNews""><tr><td>"&arrayName(col-1,n)&"</td></tr><tr><td
id='id"&n&"'><a class=""read"" href=""javascript:;""
onclick=""showNews('id"&n&"' said:
<BR>")

Next

End Function

%>



<script language="javascript">

function montre(id, shtml) {

if (document.getElementById) {

document.getElementById(id).style.visibility =
'visible';

} else if (document.all) {

document.all[id].style.visibility = 'visible';

} else if (document.layers) {

document.layers[id].visibility = 'visible';

};

var el = (document.getElementById)?
document.getElementById(id): (document.all)? document.all[id]:
(document.layers)? document.layers[id]: null;

if (!el) return;

if (typeof el.innerHTML!="undefined") {

el.innerHTML = shtml;

} else if (document.layers) {

el.document.write(shtml);ol

el.document.close();

} }

</script>



Patrice Baudin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top