Solved

Javascript syntax error

Posted on 2012-04-09
10
300 Views
Last Modified: 2012-04-10
I have the following code in an ASP/Javascript page. first part of the code (below) works fine, it detects if user is using ipad and its supposed to assing a value.

-- code --

<script type='text/javascript'>
      function isIPad(){
            var isIPad = false;
            var userAgent = '<%=Request.ServerVariables("HTTP_USER_AGENT")%>';
            alert(userAgent);
            if(userAgent.indexOf("iPad") > 0) isIPad = true;
            return isIPad;
      }
</script>

-----

then inside the html i display the content on the page depending if user is using ipad or not, that part of the code is giving me an error on the first line, below is the code and the error. Help is appreciated.

--- code ---

<%if ( isIPad() ) { %>
Not using ipad
<% } else { %>
USING IPAD
<% } %>

--- Error ---

Microsoft JScript runtime error '800a138f'

Object expected

/bluedot/Intranet/Cases/Commentspop/AddComments.asp, line 508


--- Thanks.
0
Comment
Question by:amucinobluedot
  • 5
  • 5
10 Comments
 
LVL 18

Expert Comment

by:nap0leon
Comment Utility
The stuff in between the <% and %> is not valid ASP
<%if ( isIPad() ) { %>
Not using ipad
<% } else { %>
USING IPAD
<% } %>

Open in new window


I don't see why you want to use JavaScript at all for this...

At the top of your page, use ClassicASP to look for "ipad" in the USER_AGENT and set the appropriate ASP boolean variable.  Use that variable to determine page level content.  If necessary for UI interactions, you can set that variable for javascript usage as well.

e.g..
<%
If Instr(Request.ServerVariables("HTTP_USER_AGENT"),"ipad") > 0 Then 
    isIPad = true
Else
    isIpad = false
End If
%>
<script type="text/javascript">var isIPad = <%=isIPad%></script>

Open in new window


So now you can reference server side like this:
<%
If isIPad then
    'Do stuff for iPad
Else
    'Do stuff for non-iPad
End If
%>

Open in new window


And you can reference it in your javascript like this:
<script type="text/javascript">
if (isIPad) {
    //Do iPad Stuff
} else {
    // Do non-iPad Stuff
)
</script>

Open in new window

0
 

Author Comment

by:amucinobluedot
Comment Utility
Ok, this is what I did, at the top of the page I added this code:

<%
If Instr(Request.ServerVariables("HTTP_USER_AGENT"),"ipad") > 0 Then
    isIPad = true
Else
    isIpad = false
End If
%>
<script type="text/javascript">var isIPad = <%=isIPad%></script>




On the body of the page I added:

<%
If isIPad then
    'Do stuff for iPad
Else
    'Do stuff for non-iPad
End If
%>

I get this error:

Microsoft JScript compilation error '800a03ec'

Expected ';'

/bluedot/Intranet/Cases/Commentspop/AddComments.asp, line 288

If Instr(Request.ServerVariables("HTTP_USER_AGENT"),"ipad") > 0 Then
0
 

Author Comment

by:amucinobluedot
Comment Utility
The error is now from the code on the top of the screen. This is confusing to me. i thought there are two parts. First at the top of the code with my scripts, second in the body of the page to display the content. Above are 3 parts and they all give me errors. Above error is for the top part of the code.
0
 
LVL 18

Expert Comment

by:nap0leon
Comment Utility
I added an "lcase" in two spots versus what I posted above.

save this as "ipadtest.asp" and give it a whirl.

I am: <%=Request.ServerVariables("HTTP_USER_AGENT")%><br/>
<%
If Instr(lcase(Request.ServerVariables("HTTP_USER_AGENT")),"ipad") > 0 Then
    isIPad = true
Else
    isIpad = false
End If
%>
<script type="text/javascript">var isIPad = <%=lcase(isIPad)%></script>
<%
If isIPad then
    'Do stuff for iPad
%>
  <div id="ASPSays">ASP says: This is an iPad<br></div>
<%
Else
    'Do stuff for non-iPad
%>
  <div id="ASPSays">ASP says: This is NOT an iPad<br></div>
<%
End If
%>
<div id="JSSays"></div>
<script type="text/javascript">
if (isIPad) {
  document.getElementById('JSSays').innerHTML = 'JS Says: This is an iPad'
} else {
  document.getElementById('JSSays').innerHTML = 'JS Says: This is NOT an iPad'
}
</script>

Open in new window

0
 

Author Comment

by:amucinobluedot
Comment Utility
Microsoft JScript compilation error '800a03ec'

Expected ';'

/BlueDot/testipad.asp, line 6

If Instr(lcase(Request.ServerVariables("HTTP_USER_AGENT")),"ipad") > 0 Then
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 18

Expert Comment

by:nap0leon
Comment Utility
";" is not part of ASP code...

Page runs fine locally as http://localhost/coding/ipdatest.asp
Did you change it in any way before running the asp page?
0
 

Author Comment

by:amucinobluedot
Comment Utility
No i didnt.
0
 
LVL 18

Expert Comment

by:nap0leon
Comment Utility
Then your issue is a web server issue, not a code issue.

I'm at a loss as to why your machine is throwing the error, it works fine locally.
Googling the error:

1- http://classicasp.aspfaq.com/general/why-do-i-get-800a03ec-errors.html
This one suggests an invalid character is to blame, but since the code runs fine on my machine, it's not a code error.

2- http://forums.aspfree.com/asp-development-5/microsoft-jscript-compilation-error-800a03ect-114891.html
This one suggests replacing
<% ... %> 

Open in new window

with
<script language="VBScript" runat="server"> ... </script>

Open in new window

0
 

Author Comment

by:amucinobluedot
Comment Utility
But that part is not a script, its ASP code right ?
0
 
LVL 18

Accepted Solution

by:
nap0leon earned 500 total points
Comment Utility
<% and %> are how you tell the webserver the start and stopping points of the ASP code.
For some reason, your web server is thinking the code is JScript instead of VBScript.

You can try putting your ASP code inside <script> blocks like I showed above.  Perhaps that will help.

e.g.,
<script language="VBScript" runat="server">
If Instr(lcase(Request.ServerVariables("HTTP_USER_AGENT")),"ipad") > 0 Then
    isIPad = true
Else
    isIpad = false
End If
</script>

Open in new window


But, at this point, it is NOT a code issue, it is a web-server issue of some sort (for which I am totally unqualified to assist... I know basics of setting up IIS, virtual directories, etc., but my expertise is in the code, not the webserver or the OS that it runs on)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now