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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error script not working 2

Status
Not open for further replies.

SteveHigh

Technical User
Jan 17, 2007
158
GB
Hello

I have the following script in an asp file. The script appears at the top of a page which ought to display data in a MS Access database.

It does, in fact, show the data but in the bottom left hand corner of the browser I get an 'error on page' message.

Why is it that the following will not tell me what the error is? (My IE6 is set not to display friendly HTTP messages).

Many thanks

Steve

<html>
<head>

<%
Function Insert()
Dim commandText
Dim DB
Set DB = Server.CreateObject("ADODB.Connection")
DB.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=D:\business\Form1.mdb;"

commandText = "INSERT INTO Enquiries (FullName, Sex, Country, Hobbies, DateofBirth) VALUES ('Penelope Rambottom', 'Female', 'New Zealand', 'Riding', '1977-10-13')"

DB.Execute commandText

If Err.Number <> 0 Then
Response.Write("Error (" & Err.Number & "): " & Err.Description)
DB.Close
End If

DB.close

End Function
%>
 
Hi Steve, the yellow exclaimation with "error on page" is a javascript error and not your server side script.


Cheers

Nick
 
Hello Nick

The asp page is supposed to show online some records in a table. There is no JS in the code.

The table is here:


and when you first visit it, there is no error. But if you click the button at the bottom, then the error occurs.

Do you mean that the button, in some way, is related to JS?

Thanks.

Steve
 
Steve, when you view the source of your page linked above, you have the following line:
Code:
<input type="button" value="Click me!" onclick="Insert()" />
If I had to place a guess, you either don't have a javascript function called "Insert()" which would cause the problem or you have something similarly related. The error indicates that the object does not exist, which is consistent with the fact that I see no function called "Insert()" anywhere else in your code. Take out the onclick event of the button or include the javascript function "Insert()" and see if that fixes your problem. It should.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Steve,

Also... to find the information Chopstik noted, if you double-click the error (yellow triangle with exclamation point in lower-left in I.E.), and click "Show details", it will tell you the line number and what the error is. Then, go to View > Source, and go to that line number (which in this case was the line noted above)
 
Many thanks for your helpful posts.

You are right: I do not have a JS function "Insert()". I didn't know it was a JS function!

So I need "Insert()" to go into the <HEAD> tags, don't I?

<script type="text/javascript">
some "Insert()" script here
</script>

Steve
 
Essentially, yes.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Steve, what do you actually want your button to do??

Nick
 
Hello Nickdel

Thank you for responding.

I would like it to insert a record into a table which I have online.

Cheers

Steve
 
Hello Nickel

The user will input data (name, hobbies, etc) into five fields I have in an MS Access table.

The data you see in the table link was produced using some Response.write ASP script and seems to work.

What I am trying to do now is add an input button so that a visitor can add their own data to the table.

I have this at the moment:

<%
Function Insert()
Dim commandText
Dim DB
Set DB = Server.CreateObject("ADODB.Connection")
DB.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=D:\business\Form.mdb;"

commandText = "INSERT INTO Enquiries (FullName, Sex, Country, Hobbies, DateofBirth) VALUES ('Penelope Rambottom', 'Female', 'New Zealand', 'Riding', '1977-10-13')"

DB.Execute commandText

If Err.Number <> 0 Then
Response.Write("Error (" & Err.Number & "): " & Err.Description)
DB.Close
End If

DB.close

End Function
%>

This code is behind the page link, but obviously nothing is being added. Then I saw that pressing the 'insert' button caused an error, which is when I decided to post here.

Cheers

Steve
 
Steve,

I'm not sure I understand what you're trying to ask or accomplish. You have a button which references a function that does not exist for your page. It does not submit the page (though you can change this by changing the input type to "submit" instead of "button") which would then call back to the server and allow you to execute the code in your most recent post. Nor do you have any place on your page where you allow for user entry - which presumably you would want the user to do.

If you want to make the Insert() function do the actual insert, then you cannot do this via javascript but through ASP. You could call it by checking to see if the submit button was clicked and then run from there. If you are not sure how this works or have questions in this regard, please clarify and someone can help to point you in the right direction.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Steve, I can see there is a bit of confusion here. Can I ask what level of knowledge you have regarding ASP and also general web design? Please be completely honest!

The function you have wrote above is for ASP which is server side scripting (i.e. this all gets processed on the server and then "HTML" is sent to the client browser). Javascript is client side which means it can control elements that are already visible/loaded on the browser. So basically, what I'm saying is, Javascript cannot control your function above so we dont need the onclick="Insert();" as this is referencing a Javascript function.
 
Hello Nickdel

I am happy to answer your questions. I have been involved in Web design for a few years, mainly as a hobby. I have never studied anything related to Web developemnt, IT, Windows, or computers in any academic environment.

I have never focused, either, on ASP/databases, much to my cost, preferring instead to dabble in a little ASP here, some Photoshop there, a little Flash here, and some Windows isues there.

I find that I can customise ASP and some PHP - and even a little JavaScript - but writing code from scratch to produce fading images which is done in JavaScript (as you are no doubt aware), editing a sound file in Flash MX, or creating fonts in Java (Swing) is almost certainly beyond me.

Getting back to my original insert issue, I think I will keep my ASP file (showDetails.asp) which shows my database
table and which works. Then I might need to have another ASP file which need not 'see' this showdetails.asp file, but does need to connect and open the database for me to insert records into.

Having inserted the records, I will then need to close the database. Logic suggests to me that if all this goes to plan, I need only refresh my showDetails.asp file in the browser to see the new record in place.

I know it can all be done in my existing showDetails.asp file and that is the way you yourself would probably do it, but it seems tidier to do it this way.

If you know of any tutorials which are directly relevant to creating such a separate ASP file which show how to insert a new record or records, I would be grateful. Once I have understood that, I will then attempt to update records and delete them.

Cheers

Steve
 
Hi Steve, ok what you need to look at is "forms". Forms allow a user to insert some data and then "submit" this back to the server for you to do what ever you want with. Lets look at the code you had above that you called "Function Insert()". In ASP we have 2 main types of procedures, Functions and Subs. Subs perform a specific task, like building your datatable. Functions are like Subs however they can return a value back to the rest of your page during server side processing. (Have a look here for more info:
The reason I mentioned your function above is because essentially, the code contained within the function will perform the task you require (Insert to the database, albeit you would normally use a "sub" for this). So, all we need now is a form for the user to insert some data and then submit this. The link below will get you started on user forms and how these are submitted to the server using "post" and "get".

Look here for Input forms:

Have a play about with this and if you get stuck then just pop back here with your code and we'll take a look!

Cheers

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top