Solved

Syntax for ASP/Javascript page

Posted on 2012-04-05
25
542 Views
Last Modified: 2012-06-27
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
Comment
Question by:amucinobluedot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 12
25 Comments
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37811621
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
 

Author Comment

by:amucinobluedot
ID: 37811747
Microsoft JScript compilation error '800a03ec'

Expected ';'

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

If ( isIPad() ) {

---- line 496 is:

<%If ( isIPad() ) { %>
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37811771
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:amucinobluedot
ID: 37811793
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
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37811797
try a lower case f in the word function
0
 

Author Comment

by:amucinobluedot
ID: 37811812
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
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37811825
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
 

Author Comment

by:amucinobluedot
ID: 37811892
'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
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37811939
try a lower case e in the word else
0
 

Author Comment

by:amucinobluedot
ID: 37811952
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
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37811973
this is why i hate javascript so much, its case sensitive :)

change indexOf to indexof
0
 

Author Comment

by:amucinobluedot
ID: 37811991
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
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37812000
get rid of the word then
0
 

Author Comment

by:amucinobluedot
ID: 37812015
Same error  :(
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37812112
actually, it looks like it should be indexOf - http://www.w3schools.com/jsref/jsref_indexof.asp
0
 

Author Comment

by:amucinobluedot
ID: 37812204
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
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37812226
can you post the latest code snippet you're using?
0
 

Author Comment

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

    return isIpad;

}
%>
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37812266
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
 

Author Comment

by:amucinobluedot
ID: 37812280
No, instead I get this error:

Microsoft JScript runtime error '800a138f'

Object expected

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

Author Comment

by:amucinobluedot
ID: 37812283
btw .. line 291 would be:

    alert(userAgent);
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 37812749
try changing the alert to:

alert( Request.ServerVariables("HTTP_USER_AGENT") );
0
 

Author Comment

by:amucinobluedot
ID: 37812762
still get this:

Microsoft JScript runtime error '800a138f'

Object expected

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

Author Comment

by:amucinobluedot
ID: 37812775
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
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 37812942
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
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…

739 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