How to pass file name to a Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    How to pass file name to a Function

    Hi, I am trying to send a file name to a JS function. but the problem is from I can pass some integer values for the function and i can display the alert box.
    but not for the filenames.

    this one is working:
    [HTML]<a href="javascrip t:file_down(100 1)"><img src="images_sto re/b_down.jpg" width="21" height="22" border="0" /></a>[/HTML]
    this one is Not working:
    [HTML]<a href="javascrip t:file_down(fil e_name.pdf)"><i mg src="images_sto re/b_down.jpg" width="21" height="22" border="0" /></a>[/HTML]

    Code:
    function file_down(fid)
    {
    var myvar = fid;
    alert(myvar);
    }
  • merseyside
    New Member
    • Mar 2007
    • 48

    #2
    You're missing single qouotes around the string being passed to the function.

    [HTML]<a href="javascrip t:file_down('fi le_name.pdf')"> <img src="images_sto re/b_down.jpg" width="21" height="22" border="0" /></a>[/HTML]

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      Actually In my Application I am printing these JS from PHP. thats why i couldn't put the quotes. Anyway thanks :) I'll try to fix it up.

      [PHP]echo 'href="javascri pt:file_down('. $row['p_man'].')"';[/PHP]

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You can put quotes in. Just escape them.

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          Originally posted by acoder
          You can put quotes in. Just escape them.
          Sorry , I didn't get you. how to escape it.

          [PHP]echo '<a href="javascrip t:file_down('.$ row['p_man'].')">Image Goes Here</a>';
          [/PHP]

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Code:
            \'
            Use the backslash key for escaping quotes

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              Oooops, Thanks. :)

              Comment

              Working...