What happened to my code

H

hon123456

Dear all,

I have the following java code:

<script language="javascript" type="text/javascript">

var customearray = new array(400);

for (var i=0;i<400;i++) {
customarray = "'" + <%=rs("name")%> + "'";
}

</script>

The broser complians at for (var i=0;i<400;i++) {customarray = "'"
+ <%=rs("name")%> + "'";}

It saids ";" is needed. What's wrong with my code?

Thanks.
 
X

Xu, Qian

hon123456 said:
Dear all,

I have the following java code:

<script language="javascript" type="text/javascript">

var customearray = new array(400);

for (var i=0;i<400;i++) {
customarray = "'" + <%=rs("name")%> + "'";
}

</script>

The broser complians at for (var i=0;i<400;i++) {customarray = "'"
+ <%=rs("name")%> + "'";}

It saids ";" is needed. What's wrong with my code?

Thanks.


How about change <%=rs("name")%> to <%=rs("name");%>
 
A

apatheticagnostic

Dear all,

I have the following java code:

<script language="javascript" type="text/javascript">

var customearray = new array(400);

for (var i=0;i<400;i++) {
customarray = "'" + <%=rs("name")%> + "'";
}

</script>

The broser complians at for (var i=0;i<400;i++) {customarray = "'"
+ <%=rs("name")%> + "'";}

It saids ";" is needed. What's wrong with my code?

Thanks.


What does <%= rs("name") %> expand to? Also, this is getting expanded
server-side, right?
 
H

hon123456

Dear all,
I have the following java code:
<script language="javascript" type="text/javascript">
var customearray = new array(400);
for (var i=0;i<400;i++) {
customarray = "'" + <%=rs("name")%> + "'";
}
</script>

The broser complians at for (var i=0;i<400;i++) {customarray = "'"
+ <%=rs("name")%> + "'";}

It saids ";" is needed. What's wrong with my code?

What does <%= rs("name") %> expand to? Also, this is getting expanded
server-side, right?- $Bp,i6Ho0zMQJ8;z(B -

- $Bp}<(Ho0zMQJ8;z(B -


Yes..It is server side variable . Thanks
 
H

hon123456

Dear all,
I have the following java code:
<script language="javascript" type="text/javascript">
var customearray = new array(400);
for (var i=0;i<400;i++) {
customarray = "'" + <%=rs("name")%> + "'";
}
</script>
The broser complians at for (var i=0;i<400;i++) {customarray = "'"
+ <%=rs("name")%> + "'";}
It saids ";" is needed. What's wrong with my code?
Thanks.

What does <%= rs("name") %> expand to? Also, this is getting expanded
server-side, right?- $Bp,i6Ho0zMQJ8;z(B -
- $Bp}<(Ho0zMQJ8;z(B -

Yes..It is server side variable . Thanks- $Bp,i6Ho0zMQJ8;z(B -

- $Bp}<(Ho0zMQJ8;z(B -


rs("name") is a recordset field for ASP. Thanks
 
Á

Álvaro G. Vicario

hon123456 escribió:
I have the following java code:

<script language="javascript" type="text/javascript">

var customearray = new array(400);

for (var i=0;i<400;i++) {
customarray = "'" + <%=rs("name")%> + "'";
}


I see you don't even know what language the code is in :) The main part
is JavaScript, not Java. And the <% ... %> part is ASP, which is a
server-side language: it should never reach the browser.
 
S

Stevo

hon123456 said:
Dear all,
I have the following java code:

You have the following ASP/Javascript code.
<script language="javascript" type="text/javascript">
var customearray = new array(400);

No such thing as array, you mean Array.
for (var i=0;i<400;i++) {
customarray = "'" + <%=rs("name")%> + "'";
}
</script>


You're writing to customarray instead of customearray. One of them is
spelled wrongly. Plus you're writing the same value 400 times. I'll
assume this is just because you've abstracted the real problem to a
simpler postable version.
The broser complians at for (var i=0;i<400;i++) {customarray = "'"
+ <%=rs("name")%> + "'";}
It saids ";" is needed. What's wrong with my code?
Thanks.


Perhaps "name" is returning something with quotes in it. Try commenting
that line out and replacing it with customarray="hello". That will
indicate that there's something wrong with what's being returned from
"name". It's probably got quotes in it. You could try putting an alert
in there to show what's being inserted.
 
T

Tom Cole

hon123456 escribió:
          I have the following java code:
<script language="javascript" type="text/javascript">
var customearray = new array(400);
for (var i=0;i<400;i++) {
   customarray = "'"  + <%=rs("name")%> + "'";
   }


I see you don't even know what language the code is in :) The main part
is JavaScript, not Java. And the <% ... %> part is ASP,


or JSP, it uses the same syntax and has...long before ASP even
existed.

which is a
 
L

Laser Lips

Instead of ...

customarray = "'" + <%=rs("name")%> + "'";

use ...

customarray = "'<%=rs("name")%>'";

Graham
 
L

Lasse Reichstein Nielsen

Stevo said:
Laser said:
Or even ...
customarray = "<%=rs("name")%>";


That won't work because of the nested quotes.


I'd be surprised if it doesn't work.

The quotes outside of "<%" and "%>" are in a completely different
scope and should not be considered at all when parsing the server-side
code. That, on the other hand, will be replaced by a text that,
hopefully, doesn't contain quotes before reaching the browser.

/L
 
S

Stevo

Lasse said:
Stevo said:
Laser said:
Or even ...
customarray = "<%=rs("name")%>";

That won't work because of the nested quotes.

I'd be surprised if it doesn't work.
The quotes outside of "<%" and "%>" are in a completely different
scope and should not be considered at all when parsing the server-side
code. That, on the other hand, will be replaced by a text that,
hopefully, doesn't contain quotes before reaching the browser.


Good point, I'm not a server-side person. What you say makes sense.
 
T

Thomas 'PointedEars' Lahn

Tom said:
On Apr 29, 3:20 am, "Ãlvaro G. Vicario"
[...] And the <% ... %> part is ASP,

or JSP, it uses the same syntax and has...long before ASP even
existed.

It could even be PHP, with enabled support for ASP-style tags. Possible,
but recommended against for shipping code due to possible incompatibility.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top