Skip to main content
Inspiring
March 2, 2007
Question

Can I open a recordset On Client Side Script?

  • March 2, 2007
  • 15 replies
  • 2440 views
Hi Guys,

On a form I have a client side VBscript thet checks the email addy a user has added into a text box in a form and if its in the array of values set in the script it gets refused. This works.....

I would like to adapt this a little if possible and make it so that instead of hardcoding the array values into the script, I would like to have the array values taken from a recordset because it will allow the user to add and delete bad domains via a form and not need to go into the page code to add to the array I have at the moment.

I have tried serval times to replace my array loop with a recordset while loop to get the badDomains from the field in the database but I just get script error on page in my task bar.

Can I open a recordset from a client side script?

Id apprecaiate eny thoughts on how I can do this.

Thanks again
Tag
This topic has been closed for replies.

15 replies

Tag2007Author
Inspiring
March 10, 2007
Thanks m8,
I have got myself some new books on JS and hopefully I can re do my VBS script into JS.. with any luck.. and If I can do that then I will be back to trying to connect to my recordset..
Thanks again
Inspiring
March 10, 2007
You can place VBS within <script> tags to be used with javascript, but you must put <% %> around the VBS. In one of my examples I posted earlier I used this method.

What you maybe thinking of is you can conceptually use vbscript as a client side but it will ONLY work with IE. example:

<script language="vbscript">
your code
</script>

This is hardly ever used, actually I have never seen it used, because it ONLY works with IE, it will NOT work with other browsers. If you want to use a client side language use javascript.

What you are trying to accomplish really isn't that difficult if you understand the logic behind it. All you have to do is loop through the recordset, and compare the value of the text box to each value in the recordset. You can do this either with server side VBS or client side javascript, you can even use a combination of javascript and VBS, but don't use client side VBS.
Tag2007Author
Inspiring
March 10, 2007
I will be honest envision3d you have confused me a little now,
I dont have many VBS books but have an Oriley Ref book on VBS and it says that although limited to mainly IE VBS is both a Client & server side scripting laungage?

Im sorry to dispute with you as I appreciate all feedback as a novice, but I have ran a VBS in <script> tags that I have placed in my pages Header tags that has been called from a buttons OnClick event and it runs my little script to check my bad domains array and this at present works, is this not a client script? or is that where my misunderstanding is?

I now want my current script to look at a recordset instead of its array and presumed this to be a client script looking to a servers array in the form of the recordset?

Sorry to be so thick but any comments are very welcome to aid my understanding and a pointer to documentation or tutorials are sure welcome too.

Thanks again
Tag
Tag2007Author
Inspiring
March 10, 2007
Thanks envision

That is a bit of my confusion for sure as I thought that putting VBS into script tags like <script> made it client side and putting <%%> made it server side??

Thanks again
Tag
Inspiring
March 9, 2007
To clarify things, VBS is server side only, it is not a client side scripting language. Thats why you are confused. Javascript is client side, NOT VBS.
Tag2007Author
Inspiring
March 9, 2007
Thanks envision,
Im usually not too bad with asp, but get DW to do most of my recordsets etc ,
And have always stuck to server side scripts..

Now I have to use a client script in the browser to get a recordsets data that the server scrip opens when the page loads, and im just not sure how to combine the 2 (Server side recordserd(VBS) with client side VBS activated on a forms button events) thats why I put the <%%> in my last code as I thought I had to differentiate to the browser script that it was a server recordset I was calling and using.....

Im going to try this again later and see how I go altering to you suggestions and see how I go.

Many thanks once again for your feedback I appreciate it very much, this is just for my homepage and is not nessesary as I do have it hardcoded into the page in a VBS but I would like to try it this way as its more flexible if I can get it to look to the database for ease of adding new domains or removing them without the need of opening an editor..

Thanks again

Tag
Inspiring
March 9, 2007
You are not coding properly. You cannot just throw in javascipt in with VBScript. Anything between the <% %> signs must be VBScript, and javascript must be contained within <script> tags. VBScript and javascript are completely different in syntax and structure. And sometimes when you are assigning the values to a VB variable you are puttin ing the <% %> around the value, which is not going to work. For example, you have:

counter =<%=(rsGetBadDomains_total)%>

But it should just be:

counter = rsGetBadDomains_total.RecordCount

It looks like your not really using javascript anyways so just do it all in VBScript. You can do everything you need in just a few lines of code. Also, when you are trying to assign a form value to an ASP VBScript variable you don't use javascripts document.form.control.valule method, use Request.Form("controlName"). For example you have:

sEmail = Document.Form2.email.value

it should be

sEmail = Request.Form("email")

I think you are making this more complicated than it has to be. You should loop throught your recordset and compare the form value to the recordset value. somthing simliar to:

while not rs.eof
if rs.fileds.item("badEmail").value = sEmail then
error = "Bad email"
end if
loop

Of course this is just an example and you will have to modify it to work with your application. It looks like you are just picking up ASP so I suggest that you purchase an ASP VBScript book to help you understand how ot use it.
Tag2007Author
Inspiring
March 9, 2007
I tried something a little different and I think it must be getting a record as I get a script error in the browsers status bar that says
Object Required 'hotmail'

Now I have no mention of hotmail.com in my code but hotmail is an entry in the database???

Here is the loop I tried here...

For counter = 0 to <%=(rsGetBadDomains_total)%>
sBadDomains = <%=(rsGetBadDomains.Fields.Item("sBadDomains").Value)%>

If InStr(1, sEmail, sBadDomains) > 0 Then
sValidationMessage = "You have entered an unsuitable E-Mail "
Exit For
End If

counter = counter+1
<%rsGetBadDomains.MoveNext%>
next
Tag2007Author
Inspiring
March 9, 2007
Hi Envision,
Its actually VBScript im in at the moment...

I have tried to get my client script to run but im still just not getting it although I dont think im far away, mixing client side and server side scripts to get this array loaded is still throwing me a bit !!!!!!

I tried to follow the For loop suggested in JS but did it in VBS and wondered if anyone could give it a look and point me to my errors?

I dont like just posting code without being asked as its a bit presumptious of me but Im not asking anyone to write this for just point me to my problems hopefully.....

Here is what I have , when the page loads I used DW to make a recordset for me to open the table with stored bad domains and this client script is supposed to harness the recordset created server side by DW and loop through the field and compare whats in the forms email textbox..


Sub CheckMail()

Dim sValidationMessage
Dim sEmail
Dim sBadDomains()
Dim nIndex
dim counter

sValidationMessage = ""
sEmail = Document.Form2.email.value
nIndex = 0
counter =<%=(rsGetBadDomains_total)%>

If Not (InStr(1, sEmail, "@") > 0 And InStr(1, sEmail, ".") > 0) Then
sValidationMessage = "You have entered an invalid email address!"
End If

If Len(sValidationMessage) = 0 Then

For nIndex = 0 to counter
sBadDomains(nIndex) = <%=(rsGetBadDomains.Fields.Item("sBadDomains").Value)%>


If InStr(1, sEmail, sBadDomains(nIndex)) > 0 Then
sValidationMessage = "You have entered an unsuitable E-Mail address please use your main ISP E-Mail address"
Exit For
End If

nIndex=nIndex+1
Next
End If



If Len(sValidationMessage) > 0 Then

MsgBox sValidationMessage
document.Form2.email.select
Else

document.Form2.submit()
End If

End Sub



Thanks again for all the support so far.
Regards
Tag
Inspiring
March 7, 2007
When you say client script, I am guessing you mean javascript. A recordset written is ASP is always opened on the server side, it is a server side scripting language. You cannot connect to a database with javascript because it is a client side scripting language. You can however populate a javascript array with recordset data. Something similar to:

<script type="javascript">
var myArray() = new Array;
var counter;

counter = <%=rs.RecordCount%>;

for (x=0;x<=counter;x++)
{
myArray(x) = <%= rs.fields.item("restrictedEmail").value %>;
}

</script>

Now you populated a javascript array with the data from your recordset. Of course you will need to loop through the recordset to assign the proper values, but this should give you a better idea of what to do.