peterdoherty Posted March 20, 2003 Posted March 20, 2003 Hi there I am trying to use the following javascript function with ASP code in it . The problem is that the ASP variable j never gets incremented. Can anyone spot the problem? Is there anyway that I can use the javascript variable i in the aspcode (the lstGroupMembers.Items(j).Text()) to select the next item in the list box each time the loop is iterated ? Help will be greatly appreciated. Peter <script language="javascript"> function ReturnGroup() { <% Dim j Dim sName Dim x j=0 %> //Loop around and all all the groups members to the selected text box var i; for (i=0; i< <%=lstGroupMembers.Items.Count()%>; i++) { //Get just the email address from the list <% x = Right(lstGroupMembers.Items(j).Text(), len(lstGroupMembers.Items(j).Text())- InStr(lstGroupMembers.Items(j).Text(), "(")) sName = Left(x, (Len(x)-1)) %> window.opener.document.forms['GroupEMail'].elements['<%=Page.Request.QueryString("Caller")%>'].value = window.opener.document.forms['GroupEMail'].elements['<%=Page.Request.QueryString("Caller")%>'].value + '<%= sName %>' + '<%=j%>, '; <% j=j+1 %> // THIS SEEMS TO BE ONLY EXECUTED ONCE NO MATTER HOW MANY TIMES THE JAVA LOOP IS ITERATED } } </script> Quote
LittLe3Lue Posted March 21, 2003 Posted March 21, 2003 ok ive never coded in aspx, but from what i read, i think every time you %> all your variables are fried, u have to specify them to be available for the entire site, or, for the entire user or soemthing. there was a post about keeping variables alive for pop ups, try to find that. Quote If you think that you think, but you really can't think, were you even thinking at all? Or was it just a thought, that you had been thinking a thought, that could not have been thought at all. think about my thought... why not?
Moderators Robby Posted March 21, 2003 Moderators Posted March 21, 2003 Peter, why not pass the value of sName into ReturnGroup() Quote Visit...Bassic Software
bungpeng Posted March 21, 2003 Posted March 21, 2003 You have to know ASP is server site language and javascript is client site language. ASP code will run first in webserver before javascript code, so, I don't think you code is workable... Quote
peterdoherty Posted March 21, 2003 Author Posted March 21, 2003 Thanks guys. I think I may have to put the listbox items into an array and then pass this array into the javascript function. Does any one know how I could do this? i.e. pass a VB array inot a javascript function? Cheers Quote
bungpeng Posted March 21, 2003 Posted March 21, 2003 I don't understand! Javascript can direct handle client site listbox, why you use server site control then? Quote
peterdoherty Posted March 21, 2003 Author Posted March 21, 2003 I need to use a SS Listbox because there are some db operations on some of the listbox events. The lisbox contents is controlled by a combo box selection also so the easiest way to do tis was as SS controls. I think the best thing to do would be pass an array into the javascriipt function. This array needs to be populated in VB script though in the VB back end code of the page. Does anyone know how to pass this vb array into a Javascript function? Quote
bungpeng Posted March 22, 2003 Posted March 22, 2003 You mean every time user select the combobox, your page will submit back to server and read from database, then display items in listbox? What do you think if I put my needed data from database to javascript array on page load in client site, so if user select item from combobox, I just read the needed data from javascript array and display in listbox (all done in client site). Do you think this is better? or I misunderstand your situation? Quote
peterdoherty Posted March 22, 2003 Author Posted March 22, 2003 Yep you've got it in one thets what I'm trying to do. This site is only gonna be based on an internal intranet so performance is not an issue thats why its done like this. I like your suggestion. It sounds like an excellent solution ot the problem but how would I go about doing this? I dont know how to put the data into a javascript array???? I take it then this would mean the 2 controls would be html controls rather than asp controls. Quote
bungpeng Posted March 23, 2003 Posted March 23, 2003 You need to put your Javascript in a hidden textbox. You can direct put this array in your javascript function, but it will cause you error if the array too long (my experience) My array name is "arrMenu" in this example <INPUT TYPE='hidden' NAME='hArr' VALUE='arrMenu = new Array( new Array(new Array("AAA_code","AAA_description")), new Array(new Array("BBB_code","BBB Description"),new Array("CCC_code","CCC Description"))'> In this Array, when user select first item in first combobox, then the second listbox will display "AAA_description" (only 1 item in this example); if user select the second item in first combobox, "BBB description" and "CCC description" (2 items) will display in select listbox Do you understand what I mean? function showMenuItems() { var form = document.Form1; eval(form.hArr.value); for (j=form.lstItem.length; j>=0; j--) { form.lstItem[j] = null; } for (i=0; i<arrMenu[form.cboMod.selectedIndex].length; i++) { form.lstItem.options[form.lstItem.length] = new Option(arrMenu[form.cboMod.selectedIndex][1],arrMenu[form.cboMod.selectedIndex][0]); } if (form.lstItem.length > 0) { form.lstItem.selectedIndex = 0; } } In this example javascript code, "cboMod" is my first combobox and "lstItem" is my second listbox Quote
peterdoherty Posted March 25, 2003 Author Posted March 25, 2003 Cheers but i have found a way around this - a small designchange to system. Thanks Quote
peterdoherty Posted March 26, 2003 Author Posted March 26, 2003 Wll i have chnged the design so the cbo items are aded to the parent form. Then when the actual list members are needed in the parent form they are resolved from the db. Quote
bungpeng Posted March 27, 2003 Posted March 27, 2003 Thank you. I still prefer these tasks run in client site rather than server site Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.