Solved

ASP Insert using the JavaScript Function

Posted on 2004-09-22
15
537 Views
Last Modified: 2012-08-14
What I need is that as the page unloads(or get closed), it inserts all records into the database. The database is built in MS Access. I've even used a slight JavaScript within the code. What modification shall be made in the following code ... ????

<head>
<script language="JavaScript">

      function goVal()
      {
          insertAll(document.forms[0].prod_parent.value,document.forms[0].prod_child.value);
          window.parent.close();
      }

      function insertAll(p,c)
      {
// ----- ASP insert code to be placed here          
      }

</script>
</head>

<body>
<form name="sales" method=post action="Categories.asp">
FName:<input name="fname" size=20>
<br>LName:<input name="fname" size=20>
<br><input type=button value="Submit" onClick="goVal()">
</form>
</body>

Remember the ASP Insert Code must be placed in the function, insertAll().
0
Comment
Question by:adnan_rais
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
15 Comments
 
LVL 31

Expert Comment

by:alorentz
ID: 12121750
What makes you think that you can put ASP function in Javascript?  ONly way would be to redirect to page for that:

function insertAll(p,c)
      {
      window.open("submitrecords.asp");      
      }
0
 

Author Comment

by:adnan_rais
ID: 12121879
thats so simple alorentz........... isn't there another alternate ....????
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12121894
>>thats so simple alorentz

WHy make it hard...

>>isn't there another alternate ....????

No, you cannot call ASP with Javascript.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:adnan_rais
ID: 12121905
like such

onUnload="<script>EnterValues()</script>"
0
 
LVL 31

Assisted Solution

by:alorentz
alorentz earned 25 total points
ID: 12121924
What don't you inderstand....NO...you cannot do it!

You could try XMLHTTP:

<script>
 function insertAll(p,c)
{
     var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     xmlhttp.Open("GET", "submitrecordspage.asp?p="+p+"&c="+c, false);
     xmlhttp.Send();
}

</script>

Good luck....that's all i got for ya :)
0
 

Author Comment

by:adnan_rais
ID: 12121933
any idea...???
0
 
LVL 15

Accepted Solution

by:
justinbillig earned 25 total points
ID: 12125022
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12125180
justinbillig  - where does it say anything about this in the link?
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12125327
Remote Scripting is a way to call server functions from the client.

It is IE only and it uses a java applet...

there are some other versions of remote scripting that claim to be cross browser but i have never used them so i dont know

http://www.ashleyit.com/rs/
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12125385
Yes, I know that...but this was a ASP question.  So I wasn't addressing Java.

Thanks.
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12125992
no you see it uses a java applet you dont program the java applet someone else already has done it ( Microsoft to be exact ) ... its is an answer to your asp question

"ASP Insert using the JavaScript Function"

If you want to do that you can use remote scripting ...

you call an ASP function from javascript code

read throught that article and you'll see what i am saying
0
 

Author Comment

by:adnan_rais
ID: 12130655
I mafe the code look like such. How to make it executable???? If I check the string using alert function, it displays exact data but doesn't allow to inert the record into database. So any idea ???? The Java session wasn't clearly understood to me. So plz let me know what to change in the following code to allow the data to be entered within the database.

<script language="JavaScript">

        function Insert_Prod(fname_,lname_)
        {
           var str = 'Conn.Execute("';
           str += '<%="insert into ChildProdItems(FName,LName) values('+part+','+child+')"%>';
           str += '")'
<%=str%>
//        alert(str);
        }

</script>

<body onUnload="Insert_Prod('<%=Request("fname")%>',document.forms[0].lname.value)">
<form name=sales method=post>


</form>
</body>
0
 

Author Comment

by:adnan_rais
ID: 12130664
Sorry the scripting code is as

<script language="JavaScript">

        function Insert_Prod(fname_,lname_)
        {
           var str = 'Conn.Execute("';
           str += '<%="insert into ChildProdItems(FName,LName) values('+fname_+','+lname_+')"%>';
           str += '")'
<%=str%>
//        alert(str);
        }

</script>
0
 

Author Comment

by:adnan_rais
ID: 12130825
any idea.........??? Why I'm not using XML and Java is that my Web Hosting doesn't support these both platforms. That's why I've to use the code using ASP and JavaScript
 
0
 

Author Comment

by:adnan_rais
ID: 12140340
Thanx alorentz..... Sorry to say I couldn't get ur code implemented. I've solved the matter in some other way. When I couldn't enter the recods on Unload action, I've to redirect the URL to another window and then get it closed as it loads. Anyhow I'll still grade u points as the solution was quite different from the question being asked. Thanx for all ur support guyz............
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
msxml3.dll error '80072efd' A connection with the server could be not established 8 53
Select case on click 3 27
Hide Table in merge 3 42
ASP AND XML 3 31
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question