Hiya,
I have written a search facility that looks through an access database saved on a web server and the client will end up knowing if a date is available to take a holiday to their chosen destination.
The problem is that if the database is local then no problem but if the database is on a web server then jscript errors, trying to resolve a netbios name rather than a http request.
I know there are two sides of java, client and server, and I think that I need some server side code but do not know how to code it or where to place it as the website is on geocities and I do not have any physical access to the server.
here is the java script code I have at the moment.
<SCRIPT language="JavaScript">
function searchdb(form) {
// varible init section
var TADB // tadb is the varible for the database
var ConnectionString // connectionstring is the adodbc string
var strSQL // strsql is the sql statement storage
var recnum // record number
var housenm // house name field
var startdate //holiday start date
var noofnights // number of nights field
var inc //incremental count for loop
var incinner //incremental count for loop
var prevdate //previous date for searching
var searchydate //check all permutations of date
var finalresult //if =1 then already booked
Form1.elements(6).value = "Checking, Please Wait";
TADB = new ActiveXObject("ADODB.Recordset" // Create the Recordset Object
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\\\uk.geocities.com\\cypruspremiervillas\\available.mdb";
strSQL = "SELECT * FROM holiday ORDER BY startdate DESC";// Build a SQL statement
TADB.Open(strSQL, ConnectionString, 3,1,1);// Open the recordset
// init finalresult
finalresult = 0;
// Loop through the Recordset
while(!TADB.EOF)
{
// Load date and house name variables from the Recordset
recnum = TADB.Fields.Item(0).Value;
housenm = TADB.Fields.Item(1).Value;
startdate = TADB.Fields.Item(2).Value;
noofnights = TADB.Fields.Item(3).Value;
//alert (recnum+housenm+startdate+noofnights)
// Set default value
if (housenm == null) {
housenm = 0;
}
else {
// if house field is populated then do this..
// if database has an entry that matches the drop down box then
if (housenm == Form1.elements(0).value)
{
for (inc=0; inc<Form1.elements(3).value; inc++)
{
//add days onto database booked date
var mday = Form1.elements(2).value.substr(0,2);
var mmonth = Form1.elements(2).value.substr(3,2)-1;
var myear = Form1.elements(2).value.substr(6,4);
var newDate = new Date(myear,mmonth,mday);
var newtimems=newDate.getTime()+(inc*24*60*60*1000);
newDate.setTime(newtimems);
var year=newDate.getYear();
var month=newDate.getMonth()+1;
var day=newDate.getDate();
var outerfindate = day+"/"+month+"/"+year;
prevdate = newDate;
for (incinner=0; incinner<noofnights; incinner++)
{
// replacement for addays
var mday = startdate.substr(0,2);
var mmonth = startdate.substr(3,2)-1;
var myear = startdate.substr(6,4);
var innerfindate = mday+mmonth+myear;
var newDate = new Date(myear,mmonth,mday);
var newtimems=newDate.getTime()+(incinner*24*60*60*1000);
newDate.setTime(newtimems);
var year=newDate.getYear();
var month=newDate.getMonth()+1;
var day=newDate.getDate();
var innerfindate = day+"/"+month+"/"+year;
searchydate=newDate;
//end of replacement
if (outerfindate == innerfindate)
{
finalresult=1;
}
}
}
}
}
// Go to the next Record
TADB.MoveNext();
};
// Close the Recordset
TADB.Close();
if (finalresult == 1)
{
Form1.elements(6).value = "Villa unavailable, sorry";
}
else
{
Form1.elements(6).value = "Villa is available";
}
}
//endofunc
If anyone has any idea where I go from here then that will be very appreciated.
Regards
Mark
I have written a search facility that looks through an access database saved on a web server and the client will end up knowing if a date is available to take a holiday to their chosen destination.
The problem is that if the database is local then no problem but if the database is on a web server then jscript errors, trying to resolve a netbios name rather than a http request.
I know there are two sides of java, client and server, and I think that I need some server side code but do not know how to code it or where to place it as the website is on geocities and I do not have any physical access to the server.
here is the java script code I have at the moment.
<SCRIPT language="JavaScript">
function searchdb(form) {
// varible init section
var TADB // tadb is the varible for the database
var ConnectionString // connectionstring is the adodbc string
var strSQL // strsql is the sql statement storage
var recnum // record number
var housenm // house name field
var startdate //holiday start date
var noofnights // number of nights field
var inc //incremental count for loop
var incinner //incremental count for loop
var prevdate //previous date for searching
var searchydate //check all permutations of date
var finalresult //if =1 then already booked
Form1.elements(6).value = "Checking, Please Wait";
TADB = new ActiveXObject("ADODB.Recordset" // Create the Recordset Object
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\\\uk.geocities.com\\cypruspremiervillas\\available.mdb";
strSQL = "SELECT * FROM holiday ORDER BY startdate DESC";// Build a SQL statement
TADB.Open(strSQL, ConnectionString, 3,1,1);// Open the recordset
// init finalresult
finalresult = 0;
// Loop through the Recordset
while(!TADB.EOF)
{
// Load date and house name variables from the Recordset
recnum = TADB.Fields.Item(0).Value;
housenm = TADB.Fields.Item(1).Value;
startdate = TADB.Fields.Item(2).Value;
noofnights = TADB.Fields.Item(3).Value;
//alert (recnum+housenm+startdate+noofnights)
// Set default value
if (housenm == null) {
housenm = 0;
}
else {
// if house field is populated then do this..
// if database has an entry that matches the drop down box then
if (housenm == Form1.elements(0).value)
{
for (inc=0; inc<Form1.elements(3).value; inc++)
{
//add days onto database booked date
var mday = Form1.elements(2).value.substr(0,2);
var mmonth = Form1.elements(2).value.substr(3,2)-1;
var myear = Form1.elements(2).value.substr(6,4);
var newDate = new Date(myear,mmonth,mday);
var newtimems=newDate.getTime()+(inc*24*60*60*1000);
newDate.setTime(newtimems);
var year=newDate.getYear();
var month=newDate.getMonth()+1;
var day=newDate.getDate();
var outerfindate = day+"/"+month+"/"+year;
prevdate = newDate;
for (incinner=0; incinner<noofnights; incinner++)
{
// replacement for addays
var mday = startdate.substr(0,2);
var mmonth = startdate.substr(3,2)-1;
var myear = startdate.substr(6,4);
var innerfindate = mday+mmonth+myear;
var newDate = new Date(myear,mmonth,mday);
var newtimems=newDate.getTime()+(incinner*24*60*60*1000);
newDate.setTime(newtimems);
var year=newDate.getYear();
var month=newDate.getMonth()+1;
var day=newDate.getDate();
var innerfindate = day+"/"+month+"/"+year;
searchydate=newDate;
//end of replacement
if (outerfindate == innerfindate)
{
finalresult=1;
}
}
}
}
}
// Go to the next Record
TADB.MoveNext();
};
// Close the Recordset
TADB.Close();
if (finalresult == 1)
{
Form1.elements(6).value = "Villa unavailable, sorry";
}
else
{
Form1.elements(6).value = "Villa is available";
}
}
//endofunc
If anyone has any idea where I go from here then that will be very appreciated.
Regards
Mark