Solved

Syntax for ASP/Javascript page

Posted on 2012-04-05
25
518 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
  • 13
  • 12
25 Comments
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
Comment Utility
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
Comment Utility
Microsoft JScript compilation error '800a03ec'

Expected ';'

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

If ( isIPad() ) {

---- line 496 is:

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

Assisted Solution

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

Author Comment

by:amucinobluedot
Comment Utility
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 32

Assisted Solution

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

Author Comment

by:amucinobluedot
Comment Utility
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 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
Comment Utility
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
Comment Utility
'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 32

Assisted Solution

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

Author Comment

by:amucinobluedot
Comment Utility
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 32

Assisted Solution

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

change indexOf to indexof
0
 

Author Comment

by:amucinobluedot
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
Comment Utility
get rid of the word then
0
 

Author Comment

by:amucinobluedot
Comment Utility
Same error  :(
0
 
LVL 32

Assisted Solution

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

Author Comment

by:amucinobluedot
Comment Utility
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 32

Assisted Solution

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

Author Comment

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

    return isIpad;

}
%>
0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
btw .. line 291 would be:

    alert(userAgent);
0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
Comment Utility
try changing the alert to:

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

Author Comment

by:amucinobluedot
Comment Utility
still get this:

Microsoft JScript runtime error '800a138f'

Object expected

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

Author Comment

by:amucinobluedot
Comment Utility
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 32

Accepted Solution

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

728 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

10 Experts available now in Live!

Get 1:1 Help Now