Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 561
  • Last Modified:

Syntax for ASP/Javascript page

I have the code below for an ASP/VB page, in that enviroment it detects if ipad is being used and depending on the condition displays content. I need this for an ASP/Javascript page

-- code --

Function isIPad()
    If InStr(Request.ServerVariables("HTTP_USER_AGENT"), "iPad") > 0 Then
        isIPad = True
    Else
        isIPad = False
    End If
End Function

<%If isIPad() then%>
    Code for text field here
<%Else%>
    Code for HTML editor here
<%End If%>

----

Thanks.
0
Aleks
Asked:
Aleks
  • 13
  • 12
12 Solutions
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
i assume you need this for a page thats written in javascript on the SERVER SIDE, ie: in between the <% %>?

try this:

Function isIPad()
    var userAgent = Request.ServerVariables("HTTP_USER_AGENT");
    var isIpad = false;
    If ( userAgent.indexOf("iPad") > 0 ) Then
        isIPad = True;

    return isIpad

End Function

<%If ( isIPad() ) { %>
    Code for text field here
<% } Else { %>
    Code for HTML editor here
<% } %>
0
 
AleksAuthor Commented:
Microsoft JScript compilation error '800a03ec'

Expected ';'

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

If ( isIPad() ) {

---- line 496 is:

<%If ( isIPad() ) { %>
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
make sure the isIpad function is surrounded by <% %>. Also, I can't remember if javascript is case sensitive, so try the code below:

<%
Function isIPad()
    var userAgent = Request.ServerVariables("HTTP_USER_AGENT");
    var isIpad = false;
    If ( userAgent.indexOf("iPad") > 0 ) Then
        isIPad = true;

    return isIpad

End Function
%>

<%if ( isIPad() ) { %>
    Code for text field here
<% } else { %>
    Code for HTML editor here
<% } %>
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
AleksAuthor Commented:
Still get the same error, this is all my code in those lines:

 <%if ( isIPad() ) { %>
        <label for="Comments"></label>
        <textarea name="Comments" cols="50" rows="8" id="Comments"><% if (!Lettrmrg.EOF || !Lettrmrg.BOF) { %> <%=(Lettrmrg.Fields.Item("LtrBody").Value)%>  <% } // end !Lettrmrg.EOF || !Lettrmrg.BOF %>  
        </textarea>
<% } Else { %>
     <textarea id="Comments" name="Comments" class="dmxEditor" style="width:600px;height:300px"><% if (!Lettrmrg.EOF || !Lettrmrg.BOF) { %> <%=(Lettrmrg.Fields.Item("LtrBody").Value)%>  <% } // end !Lettrmrg.EOF || !Lettrmrg.BOF %>  
</textarea>
<script type="text/javascript">
  // <![CDATA[
 jQuery(document).ready(
   function()
     {
       jQuery("#Comments").dmxEditor(
         {}
       );
     }
 );
  // ]]>
</script>
<% } %>

---

Error:

Microsoft JScript compilation error '800a03ec'

Expected ';'

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

Function isIPad()
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try a lower case f in the word function
0
 
AleksAuthor Commented:
That worked but now i get this:  

Microsoft JScript compilation error '800a03f0'

Expected '{'

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

var userAgent = Request.ServerVariables("HTTP_USER_AGENT");
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
sorry, i haven't had enough caffeine this morning :)

<%
Function isIPad() {
    var userAgent = Request.ServerVariables("HTTP_USER_AGENT");
    var isIpad = false;
    If ( userAgent.indexOf("iPad") > 0 ) Then
        isIPad = true;

    return isIpad;

}
%>
0
 
AleksAuthor Commented:
'function' and 'if' were in caps, took care of that. that part of the code seems to be ok.
Now .. where we display the content based on the values i get this error:

Microsoft JScript compilation error '800a03ec'

Expected ';'

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

} Else {


----- this is the code where my content is displayed:  ---

 <%if ( isIPad() ) { %>
        <label for="Comments"></label>
        <textarea name="Comments" cols="50" rows="8" id="Comments"><% if (!Lettrmrg.EOF || !Lettrmrg.BOF) { %> <%=(Lettrmrg.Fields.Item("LtrBody").Value)%>  <% } // end !Lettrmrg.EOF || !Lettrmrg.BOF %>  
        </textarea>
<% } Else { %>
     <textarea id="Comments" name="Comments" class="dmxEditor" style="width:600px;height:300px"><% if (!Lettrmrg.EOF || !Lettrmrg.BOF) { %> <%=(Lettrmrg.Fields.Item("LtrBody").Value)%>  <% } // end !Lettrmrg.EOF || !Lettrmrg.BOF %>  
</textarea>
<script type="text/javascript">
  // <![CDATA[
 jQuery(document).ready(
   function()
     {
       jQuery("#Comments").dmxEditor(
         {}
       );
     }
 );
  // ]]>
</script>
<% } %>
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try a lower case e in the word else
0
 
AleksAuthor Commented:
that fixed that but now i get this:

Microsoft JScript runtime error '800a01b6'

Object doesn't support this property or method

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

--- line 291 is:

    if ( userAgent.indexOf("iPad") > 0 ) Then

which takes us back to the first code, it is as of now:

<%
function isIPad() {
    var userAgent = Request.ServerVariables("HTTP_USER_AGENT");
    var isIpad = false;
    if ( userAgent.indexOf("iPad") > 0 ) Then
        isIPad = true;

    return isIpad;

}
%>
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
this is why i hate javascript so much, its case sensitive :)

change indexOf to indexof
0
 
AleksAuthor Commented:
Same error same line:

    if ( userAgent.indexof("iPad") > 0 ) Then

Microsoft JScript runtime error '800a01b6'

Object doesn't support this property or method

/bluedot/Intranet/Cases/Commentspop/AddComments.asp, line 291
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
get rid of the word then
0
 
AleksAuthor Commented:
Same error  :(
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
actually, it looks like it should be indexOf - http://www.w3schools.com/jsref/jsref_indexof.asp
0
 
AleksAuthor Commented:
I see that ... still with that i get an error.

Microsoft JScript runtime error '800a01b6'

Object doesn't support this property or method

/bluedot/Intranet/Cases/Commentspop/AddComments.asp, line 291
 
Same line of code.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
can you post the latest code snippet you're using?
0
 
AleksAuthor Commented:
<%
function isIPad() {
    var userAgent = Request.ServerVariables("HTTP_USER_AGENT");
    var isIpad = false;
    if ( userAgent.indexOf("iPad") > 0 )
        isIPad = true;

    return isIpad;

}
%>
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
do you get an alert message with this code?

<%
function isIPad() {
    var userAgent = Request.ServerVariables("HTTP_USER_AGENT");
    var isIpad = false;
    alert(userAgent);
    if ( userAgent.indexOf("iPad") > 0 )
        isIPad = true;

    return isIpad;

}
%>
0
 
AleksAuthor Commented:
No, instead I get this error:

Microsoft JScript runtime error '800a138f'

Object expected

/bluedot/Intranet/Cases/Commentspop/AddComments.asp, line 291
0
 
AleksAuthor Commented:
btw .. line 291 would be:

    alert(userAgent);
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try changing the alert to:

alert( Request.ServerVariables("HTTP_USER_AGENT") );
0
 
AleksAuthor Commented:
still get this:

Microsoft JScript runtime error '800a138f'

Object expected

/bluedot/Intranet/Cases/Commentspop/AddComments.asp, line 289
0
 
AleksAuthor Commented:
Like this ?

<%
function isIPad() {
alert( Request.ServerVariables("HTTP_USER_AGENT") );
    var isIpad = false;
alert( Request.ServerVariables("HTTP_USER_AGENT") );
    if ( userAgent.indexOf("iPad") > 0 )
        isIPad = true;

    return isIpad;

}
%>

Also gives an error
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
well, that explains why you got the last 2 sets of errors, because the server variable HTTP_USER_AGENT isnt populating correctly. its possible the variable name isIpad is conflicting with the function name, you can try changing that. other than that, i'm not sure, do you have any other errors appearing?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 13
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now