Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing an array from asp to vbscript or javascript 1

Status
Not open for further replies.

sandravega

Programmer
Feb 10, 2004
43
AR
Hi
I'm just trying to accomplish this:
I use asp to recover information from a table into an array.
I use asp because I want it in the server side... where the database is(uh, that's right, isn't it?I'm not sure)
Then I need to pass this array to an client-side function, just to repopulate a <select>. But the code says that something wrong with the array, it can't recognize it nor in vbscript nor in Javascript

I have some button like=

<input type="button" onClick="Repopulate(<%=myarray%>)" value="Repopulate Now!">

and a JavaScript function like

<script language="javascript">
function Repopulate(myarray)
var i;
objSel = document.frm1.myselect;
objSel.options.length = 0;
for (i = 0; i < myarray.length; i++)
{
var obj = new Option();
obj.value = myarray;
obj.text = myarray;
objSel.options[objSel.options.length] = obj;
}
objSel.options[0].selected = true;

end function
</script>

I know the js function does not work, it just don`t recognizes de array.

I asked this in both forums, the javascript and here...

Thank you a lot

Sandra
 
when you view the source code after the page is finished loading what do you see for myArray being printed out

e.g. (how does this look after the load)
<input type="button" onClick="Repopulate(<%=myarray%>)" value="Repopulate Now!">

___________________________________________________________________

The answer to your ??'s may be closer then you think. faq333-3811
Join the Northern Illinois/Southern Wisconsin members in Forum1064
 
Well, thank u 4 answering. It writes something like this, in the code page and in the browser window itself
(I've deleted the font tags...)

onClick="Repopulate(<p>Response object
error 'ASP 0106 : 80020005'
<p>
Type Mismatch
<p>
/central/ABM_rubro.asp
line 449
<p>
An unhandled data type was encountered.
 
that's kind of what I was expecting.

the problem is you cannot just say myarray and it will send over the array object in all.

You'll need to use the Join() and recreate the array on the client as the parameter in the function call. Then when the event occurs to call the function declare a var in the script and split the string to in all create a new javascript array.

you're input tag would look like this
Code:
<input type="button" onClick="Repopulate('<%=Join(myarray,",")%>')" value="Repopulate Now!">

Then when the function is called you will be sending a comma seperated value as in
test,test,test,test


rate off teh bat in your javascript fucntion create the new array to be used then
Code:
function Repopulate(myarray) 
myarray = myarray.split(",");
....etc..

the method I suggest using to get it over there is also discussed in this thread earlier today. thread333-843490

___________________________________________________________________

The answer to your ??'s may be closer then you think. faq333-3811
Join the Northern Illinois/Southern Wisconsin members in Forum1064
 
Thanks a lot. Really
It seems as I have broken two or more forum rules today... Sorry for that.
I've searched the forum but probably due to my uneasyness with english (I'm a spanish speaker) I couldn't find the answer.
You were helpfull in the asp-vbscript affair, and I'm always trying to improve my "forum" skills, so thank for that kind of help too.
So thanks, thanks and thanks.

Sandra
 
[smile] Thanks Sandra!

Don't be sorry, you didn't break any rules. we're just trying to keep everything as clean as possible to help us all out in the future and better help you out.

Honestly think your english is great! From my typing you would think I didn't speak any language otehr then code. ;)

Let us know if you need any more help on it

___________________________________________________________________

The answer to your ??'s may be closer then you think. faq333-3811
Join the Northern Illinois/Southern Wisconsin members in Forum1064
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top