Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2008, 03:01 PM
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBscript boolean function causes Javscript to bomb

Hi there

I have a server-side VB that runs at the beginning of the asp page, and it returns a result set, call it loResultSet.

In the client side javscript, I was trying to check to see if this result set is nothing or not.

 if (<%=(loResultSet is nothing)%>)

{

// javscript code

}



However it bombs because that (loResultSet is nothing) returns "True", as opposed to "true", and Javascript doesn't recognize True.

I know this is a dumb question, but how would you fix this, and I mean, not in a hack way, such as

if (%=(loResultSet is nothing)%>.toString().toLowerCase())



Many thanks appreciated.

CC


 
Old August 25th, 2008, 03:10 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Well, the toLowerCase() is ugly to the eye, but it's actually pretty effective.

All the other solutions will involve more code.

You might want to create a custom function just for this purpose:

Function JSBoolean( test As Boolean ) Returns String
    If test Then Return "true"
    Return "false"
End Function

You could, of course, do it with IIF:
if ( <%= IIF( loResultSet is nothing, "true", "false" )%> )

But I think I like
if ( <%= JSBoolean(loResultSet is nothing) %> )
better.

Finally, you *could* do the test in your VB code!

<% If loResultSet is Nothing Then %>
... js code for true condition ...
<% Else %>
... js code for false condition ...
<% End If %>

And that's actually the most efficient. No point in sending JS code to the browser when it won't be used.
 
Old August 25th, 2008, 03:38 PM
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks OldPendant, for your very quick reply.

We have now to change some of our codes to javascript from vbscript because of Firefox incompatibility, that's why I'm changing all the client-code. Thankfully don't have to change the server-code, that at least reduces my workload in half. :)

You're right, there doesn't seem to be one elegant solution; but at least you gave me some good pointers!

Thanks
CC






Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling VBScript Function from javascript arnabghosh Classic ASP Professional 1 July 13th, 2007 08:32 AM
VBScript find missing number function?? mat41 Classic ASP Professional 6 February 12th, 2007 07:07 PM
Calling vbscript function(passed value string) manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 0 May 7th, 2006 11:50 PM
Masterpage to include a javscript file whatagamble ASP.NET 2.0 Basics 0 March 19th, 2006 01:09 PM
Is there a round vbscript function that works? lcsgeek ASP.NET 1.0 and 1.1 Basics 8 August 20th, 2003 11:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.