473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

call procedure from onclick event of button

hi
i have some textboxes in my form wat i want to
do is wheever the user clicks the button
the data in text boxes must be stored in database
i have written my insert query like this

<script="vbscript">
<--
sub procedure cmd1_onclick()
<%
set con=server.create.....
con.open "....."

conn.execute "Insert into............"
%>
end sub

-->
</script>

the problem is whenever the page is loaded the insert query is executed
so a blank record is inserted in database and then when button is clicked again
the data is inserted
the problem is its executin the asp code in deleminators first on loadin a form
but i want that to be executed only when click event is fired for button
i only know vbscript
plz help me out
i have temporarily solved this by placin a submit button
and in its action called a form where data from textbox is requested
and then stored in database through query there and again redirecting to
first form
this is increasing my forms nd indeed is a wrong way
so plz help me out
Feb 18 '08 #1
3 19621
DrBunchman
979 Expert 512MB
Hi there,

There is nothing wrong with the way you are updating the database now! Requesting your input values, running the update and returning to the original page is a perfectly acceptable way of updating your database.

The problem you are having using a VBScript function is you have wrapped it in ASP tags and ASP runs on the server. The OnClick event occurs on the client so it can only call client side code. If you want to use a vbscript function then don't wrap it in ASP tags. e.g.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="vbscript"> 
  4.     sub TestVBScript()
  5.      msgbox("The time is " & Time) 
  6.     end sub
  7. </script>
  8. </head> 
  9. <body> 
  10. <form> 
  11. <input type="button" value="Click" onclick="call TestVBScript()"> 
  12. </form>
  13. </body> 
  14. </html> 
  15.  
Remember, you will not be able to update your database using client side functions as doing this requires ASP which is a server-side language.

I'd stick with the method you're already using.

I hope this helps,

Dr B
Feb 18 '08 #2
thanks sir
i have another question that
when the user fills textbox and clicks on submit button leaving one textbox empty then a msgbox should be shown to ask him to fill all textboxes and when he clicks on ok he should be taken to first form where only the textbox whose values were not filled should be empty other textboxes should have their original values
Feb 18 '08 #3
DrBunchman
979 Expert 512MB
Hi Chirag,

No problem. You can do this using Javascript or VBScript but as you're comfortable with VBScript we'll use that. I've commented the code below so hopefully you can see what it is doing:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <script language="vbscript"> 
  5.     sub TestVBScript()
  6.  
  7.      'CHECK WHETHER ANY OF THE TEXT BOXES ARE EMPTY (YOU CAN ADD AS MANY TEXT BOXES AS YOU NEED TO THIS CHECK)
  8.      If Document.TestForm.txtBox1.Value = "" Or Document.TestForm.txtBox2.Value = "" Then
  9.  
  10.      ' IF ANY ARE EMPTY THEN DISPLAY A MESSAGE TO THE USER
  11.      msgbox("Please fill in all text boxes!")
  12.  
  13.      ' THEN RETURN FALSE TO THE FORM SUBMIT (PREVENTS THE FORM FROM SUBMITTING)
  14.      window.event.returnValue = false
  15.      Else
  16.  
  17.      'IF ALL TEXT BOXES CONTAIN TEXT THEN RETURN TRUE (ALLOWING THE FORM TO SUBMIT)
  18.      window.event.returnValue = true
  19.      End If
  20.     end sub
  21. </script>
  22. </head> 
  23. <body> 
  24. <form name="TestForm">
  25. <input type="Text" name="txtBox1">
  26. <input type="Text" name="txtBox2">
  27. <input type="submit" value="Click" onclick="call TestVBScript()"> 
  28. </form>
  29. </body> 
  30. </html> 
  31.  
The important thing here is the window.event.returnValue. The OnClick event is fired before the form is submitted so by returning "false" we can prevent the form from doing so. Using this value you can perform all sorts of validation on your form prior to it being submitted.

I hope this helps and if you need any further help then please let me know.

Dr B
Feb 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
2
by: Vinita Sharma | last post by:
Hi All, I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is another function called on onclick...
3
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it...
2
by: Sedef | last post by:
Hi, i'm trying to create a custom Button user control which will be derived from System.Web.UI.WebControls.Button. the normal server side Button class creates some client side javascript code for...
2
by: Sandeep | last post by:
Hi I want to write onclick event on a button(a web control) ,also i want to call a client side function on the click event how to write that how to differentiate between these two events ...
5
by: RA | last post by:
I have created a button dynamically; which has been added to a TableCell of a TableRow of a Table control. Is there a way to add onclick event which calls a procedure on the Server-side itself....
1
by: saiyen | last post by:
Hey all, ive been banging my head agains the wall for a few days now, and finally decided to ask for help. i have a document that writes the header with all the javascript in it, then modifyes a...
5
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a...
8
dnb
by: dnb | last post by:
Hi Friends, i learn a phpso plz help me. i want to call a php fundtion on a onclick event of html submit button this function is work properly but i don't know how to call it on a onclick event...
21
by: brucedodds | last post by:
I have an Access 2003 form bound to a SQL Server table via ODBC. Often clicking a button on the form has the effect of requerying the form rather than firing the OnClick event. Does anyone have...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.