Solved

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

Posted on 2016-10-18
12
32 Views
Last Modified: 2016-11-11
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.


Thanks!
0
Comment
Question by:Ross Greenberg
  • 7
  • 4
12 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 41848526
Do you have an example page residing somewhere? Not quite sure what you are asking. Trying to call code behind via javascript?
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41848603
This expert suggested creating a Gigs project.
I recommend you open a GiG for this
http://www.experts-exchange/gigs
0
 

Author Comment

by:Ross Greenberg
ID: 41848611
Attached.  In place:   http://www.nhtf.net/resreg.asp
0
 

Author Comment

by:Ross Greenberg
ID: 41848690
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#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);
}
</style>

  <script type="text/javascript">


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


</script>

</head>

<body>
<p>
  <label for="NHList"></label>
  <label for="tester"></label>
</p>
<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">
      <tr>
        <td width="170"><strong>Resident Name</strong></td>
        <td width="238"><label for="RName"></label>
        <input type="text" name="RName" id="RName" /></td>
      </tr>
      <tr>
        <td height="29"><strong>Resident SSN</strong></td>
        <td><label for="RSSN"></label>
        <input type="text" name="RSSN" id="RSSN" /></td>
      </tr>
      <tr>
        <td height="29">Resident Telephone</td>
        <td><label for="RPhone"></label>
        <input type="text" name="RPhone" id="RPhone" /></td>
      </tr>
      <tr>
        <td height="26">Resident Email</td>
        <td><label for="resemail"></label>
        <input type="text" name="resemail" id="resemail" /></td>
      </tr>
      
      
      
      <tr>
        <td height="31"><strong>Resident Room</strong></td><td><label for="ResRoom"></label>
          <input type="text" name="ResRoom" id="ResRoom" /></td></tr>
      <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>
            <%
  NH.MoveNext()
Wend
If (NH.CursorType > 0) Then
  NH.MoveFirst
Else
  NH.Requery
End If
%>
          </select>
        </label></td>
      </tr>
      <tr>
        <td>Address1</td>
        <td ID="demo"><%=(NH.Fields.Item("NHAdd1").Value)%></td>
      </tr>
      <tr>
        <td>Address2</td>
        <td><%=(NH.Fields.Item("NHAdd2").Value)%></td>
      </tr>
      <tr>
        <td>City</td>
        <td><%=(NH.Fields.Item("NHCity").Value)%></td>
      </tr>
      <tr>
        <td height="23">State</td>
        <td><%=(NH.Fields.Item("NHState").Value)%>
          <label for="stasta"></label></td>
      </tr>
      <tr>
        <td>Postal Code</td>
        <td><%=(NH.Fields.Item("NHZip").Value)%>
          <label for="xyz"></label></td>
      </tr>
      <tr>
        <td>Admissions Name</td>
        <td><%=(NH.Fields.Item("NHAmish").Value)%></td>
      </tr>
      <tr>
        <td>Admissions Telephone</td>
        <td><%=(NH.Fields.Item("NHAmishPhone").Value)%></td>
      </tr>
      <tr>
        <td>Admissions Email</td>
        <td><%=(NH.Fields.Item("NHAmishEmail").Value)%></td>
      </tr>
    </table>
    <p><input name="Add Resident" type="submit" value="Save Resident" />&nbsp;
      <input type="reset" name="reset resident" id="reset resident" value="Reset Resident" />
    </p>
  </div>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
<p>&nbsp;</p>
</body>
</html>
<%
NH.Close()
Set NH = Nothing
%>
<%
Res.Close()
Set Res = Nothing
%>
<%
nh2.Close()
Set nh2 = Nothing
%>

Open in new window

0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41848691
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.
0
 

Author Comment

by:Ross Greenberg
ID: 41848969
>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?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41849059
Yes
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.

AJAX
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
          e.preventDefault();
          
           // 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
           $.ajax({
             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.
0
 

Author Comment

by:Ross Greenberg
ID: 41849129
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! :-)
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41869709
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?
0
 

Author Comment

by:Ross Greenberg
ID: 41876254
(Somebody else was able to solve this problem for me)
0
 

Accepted Solution

by:
Ross Greenberg earned 0 total points
ID: 41876255
(Somebody else was able to solve this problem for me)
0
 

Author Closing Comment

by:Ross Greenberg
ID: 41883568
no
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now