473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1. if(!isset($_POST['list'])){
  2. ?>
  3. <form action="listings.php" method="post">
  4.     <input type="hidden" name="link" value="">
  5. <?
  6. echo '<select name="list[]" multiple="multiple">';
  7. while ($row = mysql_fetch_assoc($result))
  8. {
  9.     echo '<option>' . $row['username'] . '</option>';
  10. }
  11. echo '</select>';
  12. ?>
  13. <input type="submit" name="submit" id="submit" value="Submit" />
  14. </form>
  15.  <?php } else {
  16.             $usernames = $_POST['list'];
  17.             $link="http://www.exploretalent.com/model_page.php?talentnum=";
  18.             $IDS = implode('-',$_POST['list']);?>
  19. <script type="text/javascript" >
  20.     var uids = new Array(<?php echo implode(',', $_POST['list']); ?>);
  21. </script>
  22. <a href="#" onclick="publishStream('<?php echo $link;?>',uids); return false;">Click to Publish on WALL.</a><?php }?>
  23.  
  24.  
here is the publishStream() that is called

Expand|Select|Wrap|Line Numbers
  1. function publishStream(link,IDS){
  2.                 var x;
  3.                 for (x in IDS) { //- pass in array of ids, loop through the ids here.
  4.                 streamPublish("Vote for me here", 'Visit Explore Talent', 'Checkout', link+IDS[x], "Facebook Application");
  5.             }
  6.             }
  7.  
Nov 6 '10 #1

✓ answered by gits

what about something like this?
Expand|Select|Wrap|Line Numbers
  1. <?php echo '"'.(implode('","', $_POST['list'])).'"'; ?>

8 2455
gits
5,390 Expert Mod 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. var arr = [1, 1, 2, 4, 'foo'];
Nov 6 '10 #2
the array is set up in php. im ['list'].

i am posting it in the select list.
\then i implore this variable:
Expand|Select|Wrap|Line Numbers
  1. var uids = new Array(<?php echo implode(',', $_POST['list']); ?>);
  2.  
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
Nov 6 '10 #3
gits
5,390 Expert Mod 4TB
i see that - but does:

Expand|Select|Wrap|Line Numbers
  1. <?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 ...
Nov 6 '10 #4
if i use
Expand|Select|Wrap|Line Numbers
  1. <?php echo implode('"', $_POST['list']); ?>
  2.  
i get:

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


and

Error: uids is not defined
Nov 6 '10 #5
gits
5,390 Expert Mod 4TB
it has to look like this:

Expand|Select|Wrap|Line Numbers
  1. var uids = new Array("user1", "user2", "user3");
or better:

Expand|Select|Wrap|Line Numbers
  1. var uids = ["user1", "user2", "user3"];
Nov 6 '10 #6
if i use
Expand|Select|Wrap|Line Numbers
  1.  <?php echo implode('","', $_POST['list']),'"'; ?>
  2.  
i get
Expand|Select|Wrap|Line Numbers
  1. var uids = new Array(user1","user2","user3");\n
  2.  
i cant get a " in the beginning of user1


by the way, thanks for taking some time to help me with this
Nov 6 '10 #7
gits
5,390 Expert Mod 4TB
what about something like this?
Expand|Select|Wrap|Line Numbers
  1. <?php echo '"'.(implode('","', $_POST['list'])).'"'; ?>
Nov 6 '10 #8
that worked :)

and now i click on this link:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="publishStream('<?php echo $link;?>',uids); return false;">Click to Publish on WALL.</a><?php }?>
  2.  
and if goes to this function:
Expand|Select|Wrap|Line Numbers
  1. function publishStream(link,IDS){
  2.   var x;
  3.   for (x in IDS) {
  4.   streamPublish("Vote for me here", 'Visit Explore Talent', 'Checkout', link+IDS[x], "Facebook App");
  5.   }}
  6.  
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:
Expand|Select|Wrap|Line Numbers
  1. $IDS = implode('-',$_POST['list']);?>
  2.  
Nov 6 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: danny.myint | last post by:
I was under the assumption that javascript loads all the <head></head> elements before processing the <body> tag in Mozilla/Netscape/Firefox. It doesn't seem like it, with my problem. I have...
5
by: rashmi | last post by:
how to use static function defined in one file in another file is that impposiible in 'c '
12
by: jeniffer | last post by:
Can a static function defined in a C file be ever referred (called) externally from another C file?If so in which conditions?
78
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only...
19
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
17
by: Navaidstech | last post by:
Hi all... I'm new to Java programming. I've seen how finicky java is as far case and space sensitivity sensitivity is concerned. However, I'm slowly getting hang of it. I came accross this...
3
by: ADS7328 | last post by:
Dear everybody, I trying to compile an aplication and i have got the following error during linking phase: ld: fatal: symbol `K_MultiHandler_c::~K_MultiHandler_c #Nvariant 1()' is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.