Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my first webpage with vbscript 3

Status
Not open for further replies.

haytatreides

IS-IT--Management
Oct 14, 2003
94
US
Ok...I have been searching for answers for 2 days. Forgive me if this is a dumb question, i think i killed my brain.

What i am trying to do is this:

i need a webpage that is a performance survey. It has several text fields and combo boxes. I am trying to create a vbscript that will save the data to sql server and email the data as a simple txt email. the email and data saving i think i can get down. i have the recordset, and i can do the email. here is my dilema. i need to verify that the user should be allowed to fill out a survey. the user is given a number, and i want them to type that number in an inputbox to verify that they can continue. i thought i had it written pretty well, and that i was a stud, but just like always i was wrong.

i am trying to use an onLoad sub to display an input box, and then i would test the input based on the recordset of possible entries. i can't get the inputbox to popup.

any help at all will be appreciated.

hayt
 
Try this:

Code:
<HTML>
<HEAD>
<TITLE>Test PopUp</TITLE>

<script language="VBScript">
Sub DisplayPopup
	Dim strTmp
	
	strTmp = "<input type='text' id='varTxt1' name='varTxt1'>"
	divPopUp.innerHTML = strTmp
	
End Sub

Sub DisplayVal
	MsgBox "Typed value: " & varTxt1.value
End Sub

</script>

</HEAD>
<BODY onLoad="DisplayPopup()">

<div id="divPopUp" name="divPopUp"></div>
<input type="button" value="Test" onClick="DisplayVal()">

</BODY>
</HTML>
 
Rob94

thanks for the code, but right before you posted i got my inputbox to load. the only problem is that it doesn't matter what the hell i put in it, it just goes to the page. i don't know how to get it to reload until they put in a number that matches my recordset. is my connection to my db bad? or my code? or both? here is my code....i need all the help you can give.

hayt


<HTML>
<HEAD>
<TITLE>Survey Form</TITLE>
<Script Language="VBScript" Runat="server">
Option Explicit

Dim myConn
Dim myRecordset
dim DB_Connect_String
Dim strSurveyMail, rstSurvey, strColumn1, mailTo
Dim strOne, strTwo, strThree, strFour, strFive, strComments
mailTo = "im@yourdomain.com"

DB_Connect_String ="driver={SQL Server};server=myServer;database=myDatabase"

Set myConn = CreateObject("ADODB.Connection")
set myRecordset = CreateObject("ADODB.Recordset")

myConn.Open = DB_Connect_String

strSurveyMail = "select Column1, Column2 from Table Where Column2 = '1';"

myRecordset.Open strSurveyMail, myConn

Set rstSurvey = myRecordset

sub window_onload
Dim inputWO

inputWO = Inputbox("Enter your Survey Number")
If Not (rstSurvey.Eof and rstSurvey.Bof) Then
While Not rstSurvey.Eof
strColumn1 = rstSurvey("Column1")
If inputWO = strColumn1 Then
msgbox = "Thank you."
exit sub
End If
rstSurvey.MoveNext
Wend
msgbox = "Sorry. That number is bad. BAD!!"
location.reload(true)
End If
end sub
</Script>
</HEAD>
<BODY>
...

 
haytatreides,

Do you know how to test to see if you are actually pulling back data from your SQL datasource? You might not be connecting correctly to the data. One way you can accomplish this is by defining an ODBC System DSN and connect to your data that way. You stated in your previous post that it doesn't matter what you put in the input box, it just basically loads the page. You defined some message boxes in the code, do you see any of them appear after you type in a value in your input box?


 
none of the msgboxes load, and to be honest, the inputbox just stopped loading. i am clearing my cahche and testing again. as far as testing my connection, to be honest, i do not know how to do that.
hayt
 
ok...i am an idiot. i got an error

illegal assignment on "msgbox"

is it case sensitive? i don't entirely know the syntax.
 
ok, i got it. i needed to put msgbox "blah" and not msgbox = "blah"

But now it will not check the correct survey number when i put it in, and is there any way to get the browser to go "back" when i hit "cancel"?
 

Insert the code snippet below between the following 2 statements of your original code:

Set rstSurvey = myRecordset
sub window_onload

Code:
If Not (rstSurvey.Eof and rstSurvey.Bof) Then
  MsgBox "I have data to work with."
Else
  MsgBox "Something is wrong."
End If

It should look like this:

Code:
Set rstSurvey = myRecordset

If Not (rstSurvey.Eof and rstSurvey.Bof) Then
  MsgBox "I have data to work with."
Else
  MsgBox "Something is wrong."
End If    

sub window_onload

When you run the code, you should see the appropriate message based upon if you set things up correctly or not. Let me know what it says, and we'll go from there....
 
ok, i got it and even tested by creating a msgbox to display the first record, the problem now is that when i type in the exact data, it fails.

Sorry to be a pain.

hayt
 
What is the type of Column1 in your Table ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
When you say "it fails", do you mean you see the messagebox pop-up that says "Something is wrong.", or that there is some sort of syntax error on the screen?
 
column1 is int. and i am guessing that the input from the user is string? could that be it?

it fails the if statement. i got the connection, and my recordset pulls the correct data (tested in query analizer and w/ msgbox to display variable). strColumn1 = 1253 and inputWO = 1253 and it fails the if statement.

should i convert the strColumn1 to string? or the inputWO to int? and if so, how?
 
I would try this:
If CLng(inputWO) = CLng(strColumn1) Then
Anyway, I would do some sanity checking before, something like:
If Not IsNumeric(inputWO) Then

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Try this:

In your WHILE statement, change this:
Code:
If inputWO = strColumn1 Then
  msgbox = "Thank you."    
  exit sub
End If

to look like this:
Code:
If CStr(Trim(inputWO)) = CStr(Trim(strColumn1)) Then
  msgbox = "Thank you."    
  exit sub
End If

This will convert both values to "string" datatypes and trim the excess spaces (if any) before and after the values. Not sure if you need to do the compare as an integer or string type however...
 
YOU ARE BOTH GENIUSES!!!

I know u are both tryin for that mvp of the month!

I am now going to test my other functions(the difficult ones). Thanks so much to you both. I can sleep now.

hayt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top