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.
LVL 1
AleksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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 MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
get rid of the word then
0
AleksAuthor Commented:
Same error  :(
0
Big MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.