Using parameter variable as ID name?

Discussion in 'JavaScript' started by Crayz, Nov 19, 2008.

  1. #1
    Edit: Disregard this question, I had an issue passing my third parameter to my JS function, which happened to be the variable I was questioning :)
    Silly thread by me =\

    Hello, seeing as how I'm not experienced with javascript syntax, I would like to know how to pass a variable as string in such a way below:

    function showUser(c)
    { 
      document.getElementById("txtHint");
      // document.getElementById(c); (I would like to use variable c in place of the ID name.  I'm not sure of the proper syntax, though.
    }
    
    showUser(<?=$count?>);
    Code (markup):
    Any suggestions?
    thanks!
     
    Crayz, Nov 19, 2008 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi,
    the only thing you need to do is to say JS, that the argument in your function is a string, using whatever quotes - showUser('<?=$count?>');
    Without that, you're passing the value of php $count as a JS variable... Hope you see what I mean
     
    lp1051, Nov 19, 2008 IP