Aleks
asked on
Javascript syntax error
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.ServerVariable s("HTTP_US ER_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/Co mmentspop/ AddComment s.asp, line 508
--- Thanks.
-- code --
<script type='text/javascript'>
function isIPad(){
var isIPad = false;
var userAgent = '<%=Request.ServerVariable
alert(userAgent);
if(userAgent.indexOf("iPad
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/Co
--- Thanks.
ASKER
Ok, this is what I did, at the top of the page I added this code:
<%
If Instr(Request.ServerVariab les("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/Co mmentspop/ AddComment s.asp, line 288
If Instr(Request.ServerVariab les("HTTP_ USER_AGENT "),"ipad") > 0 Then
<%
If Instr(Request.ServerVariab
isIPad = true
Else
isIpad = false
End If
%>
<script type="text/javascript">var
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/Co
If Instr(Request.ServerVariab
ASKER
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.
I added an "lcase" in two spots versus what I posted above.
save this as "ipadtest.asp" and give it a whirl.
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>
ASKER
Microsoft JScript compilation error '800a03ec'
Expected ';'
/BlueDot/testipad.asp, line 6
If Instr(lcase(Request.Server Variables( "HTTP_USER _AGENT")), "ipad") > 0 Then
Expected ';'
/BlueDot/testipad.asp, line 6
If Instr(lcase(Request.Server
";" 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?
Page runs fine locally as http://localhost/coding/ipdatest.asp
Did you change it in any way before running the asp page?
ASKER
No i didnt.
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
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
<% ... %>
with <script language="VBScript" runat="server"> ... </script>
ASKER
But that part is not a script, its ASP code right ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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..
Open in new window
So now you can reference server side like this:
Open in new window
And you can reference it in your javascript like this:
Open in new window