473,387 Members | 1,423 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,387 software developers and data experts.

Function is not working in javascript

11
Hi,

I'm writing a code which calls the javascript function through button click in ASP. But i fear , the function is executed before onclick.

Here is my code.
<html>
<body>
<%asp code here%>
<script language=javascript>
function insert()
{
<%
rs_qry="insert into t1 values(a,b)"
set res=conn.execute rs_qry
%>
alert("hai") // this is to test whether the function is called.
}
</script>

<input type =button value=b1 runat=server onclick="javascript:insert()">

---

now while i execute the page, before clicking on the button, the data get inserted into the table.
But hte alert box is coming only after clicking the button. This confuses me whether the function is working properly.

moreover the function doesn't work when put inside the head part of html.

Please help me in resolving this issue.

Thanks in advance.
May 25 '07 #1
4 1775
javascript runs on client side whereas vbscript runs on server side.
your function contains the vbscript coding.so when u run the page vbscript coding get executed on server n the html coding with executed result on server u got.
n when u click on the button, only client side coding will get executed n the alert msg is coming.
May 25 '07 #2
deedi
11
Hi Dipti,

Can you please suggest me a solution for my problem? My requirement is, I've populated data from db to asp page in tabular format. Each row contains a checkbox field also. When the user clicks the checkbox and give sumbit, the corresponding columns in the rows needs to be inserted into the table along with other fields(which i won't show to the user).

I'm stuck. Please provide your suggestions.

Regards,
Deedi.
May 29 '07 #3
Hi deedee

u take a button and onsubmit write this code:

<........ onsubmit="document.formname.action=' ';document.formname.submit=' ' " />

this will post the values of fields of ur form to this page itself.

now u can check wether the checkbox is checked or not by:-

if request.form("chk") then
//write the coding to add fields in database
// e.g. rs("field1")=request.form("name")
else
//the coding which will show the data as u want to come for the first time the page run.

end if


Note:
if u don't want to come at this page again then do as u were doing with submit button....
and call the another page by action='.....' in the <form.....>
and add the code in the second page to add the records in database...

if request.form("chk") then
//write the coding to add fields in database
// e.g. rs("field1")=request.form("name")
end if

now it depends how u have shown the values to user....if u r showing just in a simple table then u have to store those values to hidden fiels also so that those can be taken at other page..or if they were coming from the database then u can access those values at other page also n save to as u want.
May 30 '07 #4
deedi
11
Hey Thanks Dipti, it worked. Thanks a lot.
May 30 '07 #5

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

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
9
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
2
by: Chris | last post by:
I am new to these forums and hope I am in the right place! I am working on an ASP (3.0) page that displays hotel data from a recordset in a table. In the last column of each row, I want to...
14
by: Paul | last post by:
Hi I have 2 functions in java script, one opens a second window-this works, the other is supposed to close this second window, does not seem to be working. Just wondering if anyone had any ideas....
1
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1"...
5
by: Mangler | last post by:
I am having trouble with a JavaScript Function that includes ASP in it. The function almost works, I was wondering if someone can take a look at it to see if the ASP in the function is the cause of...
1
by: zebra242 | last post by:
I'm working to get the onLoad function of a javascript to work: the script allows form buttons in html to refer to labeled frames in flash. Which works fine. Now I want to add onLoad...
13
vikas251074
by: vikas251074 | last post by:
When change the <script language="javascript"> to <script type="text/javascript">, javascript function now works no more. Previously it was working. Javascript function is given below - function...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.