Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 49
  • Last Modified:

Needed: ASP/JavaScript coder. Short term. Maybe 2-3 hrs if'n you are good

I have an .asp page on which there is a form that has a select/option/value/OnChange element with the initial values are set from a Records/fields of an MSAccess Database.The user will peruse the contents of the select box eventually picking out a record at which point the OnChange "action" takes over and calls a function residing in that page's header. The problem is that function will be in JavaScript and therefore not allowing me access to that database – or to any other.

The question is how can I provide the same functionality as the above without ever leaving the ASP code?

I'll need an hourly quote and a guesstimate of how many hours.

Ross Greenberg
Ross Greenberg
  • 7
  • 4
1 Solution
Randy PooleCommented:
Do you have an example page residing somewhere? Not quite sure what you are asking. Trying to call code behind via javascript?
Julian HansenCommented:
This expert suggested creating a Gigs project.
I recommend you open a GiG for this
Ross GreenbergAuthor Commented:
Attached.  In place:   http://www.nhtf.net/resreg.asp
Technology Partners: 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!

Ross GreenbergAuthor Commented:
<!--#include file="../../../nhtf/Connections/fred.asp" -->
Dim NH
Dim NH_cmd
Dim NH_numRows

Set NH_cmd = Server.CreateObject ("ADODB.Command")
NH_cmd.ActiveConnection = MM_fred_STRING
NH_cmd.CommandText = "SELECT * FROM NursingHomes" 
NH_cmd.Prepared = true

Set NH = NH_cmd.Execute
NH_numRows = 0
Dim Res
Dim Res_cmd
Dim Res_numRows

Set Res_cmd = Server.CreateObject ("ADODB.Command")
Res_cmd.ActiveConnection = MM_fred_STRING
Res_cmd.CommandText = "SELECT * FROM [NursingHomes]" 
Res_cmd.Prepared = true

Set Res = Res_cmd.Execute
Res_numRows = 0
Dim nh2__MMColParam
nh2__MMColParam = "1"
If (Session("nhid") <> "") Then 
  nh2__MMColParam = Session("nhid")
End If
Dim nh2
Dim nh2_cmd
Dim nh2_numRows

Set nh2_cmd = Server.CreateObject ("ADODB.Command")
nh2_cmd.ActiveConnection = MM_fred_STRING
nh2_cmd.CommandText = "SELECT * FROM NursingHomes WHERE ID = ?" 
nh2_cmd.Prepared = true
nh2_cmd.Parameters.Append nh2_cmd.CreateParameter("param1", 5, 1, -1, nh2__MMColParam) ' adDouble

Set nh2 = nh2_cmd.Execute

nh2_numRows = 0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Resident Registration</title>
<style type="text/css">
body {
	background-image: url(../../../nhtf/Stucco.gif);

  <script type="text/javascript">

function changeFunc(xx)
var nhid2 = xx; 
var fred = "SELECT * FROM NursingHomes WHERE ID =" + xx;



  <label for="NHList"></label>
  <label for="tester"></label>
<h2 align="center">Resident Registration</h2>
<form id="form1" name="form1" method="post" action="">
  <h3 align="center">(Required fields are in <strong>bold</strong>)</h3>
  <div align="center">
    <table width="487" border="1" id="RDetails">
        <td width="170"><strong>Resident Name</strong></td>
        <td width="238"><label for="RName"></label>
        <input type="text" name="RName" id="RName" /></td>
        <td height="29"><strong>Resident SSN</strong></td>
        <td><label for="RSSN"></label>
        <input type="text" name="RSSN" id="RSSN" /></td>
        <td height="29">Resident Telephone</td>
        <td><label for="RPhone"></label>
        <input type="text" name="RPhone" id="RPhone" /></td>
        <td height="26">Resident Email</td>
        <td><label for="resemail"></label>
        <input type="text" name="resemail" id="resemail" /></td>
        <td height="31"><strong>Resident Room</strong></td><td><label for="ResRoom"></label>
          <input type="text" name="ResRoom" id="ResRoom" /></td></tr>
        <td height="26"><strong>Resident Nursing Home </strong></td>
        <td><label for=" NHName">
          <select name=" NHName" size="1" id=" NHName" title="<%=(NH.Fields.Item("NHName").Value)%>" onchange="changeFunc(value)">
While (NOT NH.EOF)
            <option value="<%=(NH.Fields.Item("ID").Value)%>"><%=(NH.Fields.Item("NHName").Value)%></option>
If (NH.CursorType > 0) Then
End If
        <td ID="demo"><%=(NH.Fields.Item("NHAdd1").Value)%></td>
        <td height="23">State</td>
          <label for="stasta"></label></td>
        <td>Postal Code</td>
          <label for="xyz"></label></td>
        <td>Admissions Name</td>
        <td>Admissions Telephone</td>
        <td>Admissions Email</td>
    <p><input name="Add Resident" type="submit" value="Save Resident" />&nbsp;
      <input type="reset" name="reset resident" id="reset resident" value="Reset Resident" />
Set NH = Nothing
Set Res = Nothing
Set nh2 = Nothing

Open in new window

Julian HansenCommented:
The question is how can I provide the same functionality as the above without ever leaving the ASP code?
ASP runs on the server, completes - output goes to the browser. ASP no longer plays a role.

Two options
1. You AJAX the data back to the server
2. You post it back

JavaScript cannot access the database directly but it can make a call to a service (script) on the server using AJAX (or as a form post) with the data that needs to be added to the database and the server script can then do the necessary.
Ross GreenbergAuthor Commented:
>ASP runs on the server, completes - output goes to the browser. ASP no longer plays a role.

I use Dreamweaver. Most of the code that it cuts runs on the server with the output then being shown in the browser. My problem is that upon an OnChange event a function in the header and in JavaScript is called yet I'm not done with the database.

>Two options
>1. You AJAX the data back to the server
>2. You post it back

I do not know AJAX. Is it difficult to learn? Are there decent examples around or toolboxes?

>JavaScript cannot access the database directly but it can make a call to a service (script) on the server using AJAX (or as a >form post) with the data that needs to be added to the database and the server script can then do the necessary.

So for me to "pop back" into ASP I need only post/submit/action from JavaScript?
Julian HansenCommented:
The cycle works like this

Request to server (yourpage.asp)
Server triggers ASP handler
ASP handler reads and processes script
Script produces output (HTML)
HTML is sent back to the browser (ASP ceases to exist)
Browsers receives HTML - has no knowledge that ASP had a role.
Browser starts rendering page
Browser downloads resources (img / script / css) as it finds them (async)
Browser executes any raw script it finds (script not set to run on document ready)
As resources complete downloading browser incorporates them into the document.
Render completes onready scripts fire.

User interacts with document (clicks, enters data etc)
Default browser behaviour handles button clicks and form submits.
Forms by default submit to where the action attribute points (if missing back itself) using the method defined by the method attribute (GET by default - POST if specified).

Either of the above sends a request back to the server (to the url specified in the action) along with the form data as part of the URL (GET) or as part of the request payload (POST)

Script processes request and sends output back and so the process repeats.

In essence AJAX uses the same principle but it does it behind closed doors so from the user experience the page does not change.

Instead of allowing browser default behaviour for a form submit - you use JavaScript to bind an event handler to the submit event and you override it - you disable the default behaviour so the form does not POST back to the server.

Your JavaScript routine then makes a request (exactly the same as if the default behaviour had executed - except in the background so it does not affect the state of the page). This request happens asynchronously and any data the server would have sent to the browser window goes instead to the AJAX callback which is your code that you then configure to do with the return what you need to.

The JQuery library makes AJAX quite easy

// The first line says run this code only when the document is ready
$(function() {
   // bind to the form submit
   $('#myform').submit(function(e) {
          // prevent default form behaviour
           // JQuery gives us a method to get all the form data
           // exactly as if we did a form submit
           // formdata will now look like this
           // field1=value1&field2=value2 ....
           // you can append any custom values you want with &key=value
           var formdata = $(this).serialize();
           // Make the AJAX call
             url: 'serverscript.asp', // The script that processes the response
             data: formdata,
             type: 'POST',
             dataType: 'JSON', // SEE DISCUSSION BELOW
            // Chained callback - invoked when AJAX call completes
            .done(function(resp) {
                // resp holds the resp from the server
                // not familiar with SweetAlert but  you would invoke it here
                // sweetAlert(resp.message);
                // res.message is something I made up - this part is defined by
                // you - if you send back a JSON object that has a property message in it
                // then resp.message will access that property. If you included a property called
                // status in your return then resp.status would be how you access that
                // If you don't use JSON and just send back a string then resp will hold the string

Open in new window

That's AJAX - the dataType above with JSON - your server script will return data in whatever form you program it to. You can send a string back "Database update successful" - in which case you would omit the dataType property and the resp parameter of the done() callback will be the string.
If you specify JSON then your script can send back an object with properties and sub-properties in JSON format - the dataType: "JSON" tells JQuery that the return is a JSON object and it parses the return so that resp is a JavaScript object.

More about jQuery AJAX here

On the server side you would process the data exactly the same as a form post. The only difference is when you are done you don't render out a whole page - you only output what data you want to be sent back to the AJAX routine so that it can wrap up the process from the Browser / User side.
Ross GreenbergAuthor Commented:
Well, Gosh!

This changes my view of things entirely. I had thought that all webpages were client-side with the only occasional trips to the server, such as to open a database retrieve a record, operate upon that record and then to go back to the client-side webpage already in progress. Now you're saying that all webpages reside on the server and express themselves in HTML as emitted from time to time. Well my-oh-my – that's a little bit different. My paradigm has been working well for me for a few decades. Forgive me as I catch my breath! :-)
Julian HansenCommented:
I am not sure I follow you.

Server delivers content to browser.
Browser processes t hat content within the browser - connection with server is effectively lost (you can use sockets and keep the connection open and continue to exchange data - but you need to specifically code that)
How the browser sends data back is dependent on how you code your html page.
By default, without any intervention, forms post data back to the server, the server script operates on the data and sends back the next page.
AJAX allows you to post back to the server in the background - without the page changing.

That's the essence of it - not sure if there was a question in your last post?
Ross GreenbergAuthor Commented:
(Somebody else was able to solve this problem for me)
Ross GreenbergAuthor Commented:
(Somebody else was able to solve this problem for me)
Ross GreenbergAuthor Commented:

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now