Passing ASP array into javascript function

Discussion in 'ASP General' started by Patrice, Apr 1, 2004.

  1. Patrice

    Patrice Guest

    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
     
    Patrice, Apr 1, 2004
    #1
    1. Advertising

  2. Patrice

    swp Guest

    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

    "Patrice" <> wrote in message news:<WzPac.182483$>...
    > 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
     
    swp, Apr 1, 2004
    #2
    1. Advertising

  3. Patrice

    Dominique Guest

    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" <> wrote in message
    news:WzPac.182483$...
    > 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
    >
    >
     
    Dominique, Apr 1, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan Underwood
    Replies:
    2
    Views:
    677
    Simon Biber
    Aug 13, 2003
  2. =?utf-8?B?5YiY5piK?=
    Replies:
    4
    Views:
    467
    Bo Persson
    Jul 26, 2007
  3. Alex
    Replies:
    4
    Views:
    38,148
    chewbacca
    Jul 15, 2008
  4. someone
    Replies:
    26
    Views:
    902
    Jorgen Grahn
    Oct 24, 2011
  5. Joe Van Dyk
    Replies:
    2
    Views:
    106
    Joe Van Dyk
    Sep 12, 2006
Loading...

Share This Page