function not defined problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • patrioticcow
    New Member
    • Sep 2010
    • 15

    function not defined problem

    hello.
    i get returned this error "user1 not defined".

    the user1, user1, ... are an array
    but somewhere is getting stuck

    thanks a lot,

    here is my code
    Code:
    if(!isset($_POST['list'])){
    ?>
    <form action="listings.php" method="post">
        <input type="hidden" name="link" value="">
    <?
    echo '<select name="list[]" multiple="multiple">';
    while ($row = mysql_fetch_assoc($result))
    {
        echo '<option>' . $row['username'] . '</option>';
    }
    echo '</select>';
    ?>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </form>
     <?php } else {
                $usernames = $_POST['list'];
                $link="http://www.exploretalent.com/model_page.php?talentnum=";
                $IDS = implode('-',$_POST['list']);?>
    <script type="text/javascript" >
        var uids = new Array(<?php echo implode(',', $_POST['list']); ?>);
    </script>
    <a href="#" onclick="publishStream('<?php echo $link;?>',uids); return false;">Click to Publish on WALL.</a><?php }?>
    here is the publishStream() that is called

    Code:
    function publishStream(link,IDS){
                    var x;
                    for (x in IDS) { //- pass in array of ids, loop through the ids here.
                    streamPublish("Vote for me here", 'Visit Explore Talent', 'Checkout', link+IDS[x], "Facebook Application");
                }
                }
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    how doe's the JavaScript-array really look like? is it a valid JavaScript-array? is the array in any way extended by an additional lib (jQuery or whatever)? basically a JavaScript-Array must look like:
    Code:
    var arr = [1, 1, 2, 4, 'foo'];

    Comment

    • patrioticcow
      New Member
      • Sep 2010
      • 15

      #3
      java array

      the array is set up in php. im ['list'].

      i am posting it in the select list.
      \then i implore this variable:
      Code:
      var uids = new Array(<?php echo implode(',', $_POST['list']); ?>);
      witch is gonna return everything from the usernames field from my database.
      then i send each result to that function

      but i get that the results that come from UIDS (like: user1, user2, ...) are not defined

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        i see that - but does:

        Code:
        <?php echo implode(',', $_POST['list']); ?>
        writes a comma separated list of strings or numbers? note that when it writes the values and those values should be strings then you would need to add the quotes around every element - otherwise that values are treated as variables that are of course undefined ...

        Comment

        • patrioticcow
          New Member
          • Sep 2010
          • 15

          #5
          if i use
          Code:
          <?php echo implode('"', $_POST['list']); ?>
          i get:

          Error: missing ) after argument list
          Source Code:
          var uids = new Array(user1"use r2"user3");


          and

          Error: uids is not defined

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            it has to look like this:

            Code:
            var uids = new Array("user1", "user2", "user3");
            or better:

            Code:
            var uids = ["user1", "user2", "user3"];

            Comment

            • patrioticcow
              New Member
              • Sep 2010
              • 15

              #7
              if i use
              Code:
               <?php echo implode('","', $_POST['list']),'"'; ?>
              i get
              Code:
              var uids = new Array(user1","user2","user3");\n
              i cant get a " in the beginning of user1


              by the way, thanks for taking some time to help me with this

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                what about something like this?
                Code:
                <?php echo '"'.(implode('","', $_POST['list'])).'"'; ?>

                Comment

                • patrioticcow
                  New Member
                  • Sep 2010
                  • 15

                  #9
                  that worked :)

                  and now i click on this link:
                  Code:
                  <a href="#" onclick="publishStream('<?php echo $link;?>',uids); return false;">Click to Publish on WALL.</a><?php }?>
                  and if goes to this function:
                  Code:
                  function publishStream(link,IDS){
                    var x;
                    for (x in IDS) {
                    streamPublish("Vote for me here", 'Visit Explore Talent', 'Checkout', link+IDS[x], "Facebook App");
                    }}
                  the trick here is this IDS[x] to take one by one the whatever is returned from that array

                  the IDS are defined like this:
                  Code:
                  $IDS = implode('-',$_POST['list']);?>

                  Comment

                  Working...