JavaScript Forum JS Made Easy: Free JavaScripts Tutorials Example Code
About This Product
FontsMadeEasy.com
 
The Business Internet
Find it on This page:
 
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet

     
Jsmadeeasy Forums Home   Search   Login   Register   Member List  
JS Made Easy  > JavaScript programming  > onclick error with function call and passing values  
 
Display using:  
Previous Thread :: Next Thread 
 Author Thread: onclick error with function call and passing values
gakman_2006 is not online. Last active: 2/14/2006 12:43:20 PM gakman_2006
Joined: 14 Feb 2006
Total Posts: 1
 
onclick error with function call and passing values
Posted: 14 Feb 2006 12:43 PM
I am trying to get an onclick event to pass some values to a function to display in an alert box for now. I can get it sort of working but now the way I need it. I will be changing the alert in the function to open in a new window after I get the onclick call working properly.

I read from an array to get my names then I want to click on the link to get the rest of the info for that person.

If you change the for loop line to be from names_array.length to names_array.length-1
the values of the last item in the arrays get passed to the function and it does not matter what link gets clicked. I need it to pas the correct values from the correct line that gets clicked.

Any help anyone can give me would be greatly apprieciated

Thanks Glen



CODE
<script language="javascript" type="text/javascript">
<!--

// Names parallel Array

var names_array = new Array();

names_array[0] = 'Bob';
names_array[1] = 'Sally';
names_array[2] = 'Henry';
names_array[3] = 'Gerry';
names_array[4] = 'Betty';



// Phone parallel Array

var phone_array = new Array();

phone_array[0] = '555-1111';
phone_array[1] = '555-2222';
phone_array[2] = '555-3333';
phone_array[3] = '555-4444';
phone_array[4] = '555-5555';


// Address parallel Array

var address_array = new Array();

address_array[0] = 'Vancouver\, BC';
address_array[1] = 'Calgary\, Alberta';
address_array[2] = 'Saskatoon\, Sask';
address_array[3] = 'Winnipeg\, Manitoba';
address_array[4] = 'Toronto\, Ont';


for (i = 0; i < names_array.length; i++) {

document.write('<a href="#" onclick="passNames(names_array[i], phone_array[i], address_array[i]);">Click to see Info ' + names_array[i] + ' \<\/a>');
document.write("<hr />");

}

function passNames(name1,name2,name3) {

alert(name1 + " - " + name2 + " " + name3);

}
-->
</script>

END CODE
Previous Thread :: Next Thread 
Page 1 of 1
 
Jsmadeeasy.com  > JS Made Easy  > JavaScript programming  > onclick error with function call and passing values