I could automatically load the system date and time in html text boxes using the below java scripting function in html body onload:
Code:
<script language="javascript">
function msg()
{
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
date1.value = month + "/" + day + "/" + year; //date1 is textbox name and id
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if ((minutes < 10) && (hours > 11))
{
minutes = "0" + minutes
}
time1.value = hours + ":" + minutes + " " + "PM"
if ((minutes < 10) && (hours < 11))
{
minutes = "0" + minutes
}
time1.value = hours + ":" + minutes + " " + "AM"
}
</script>
I want my html textboxes input to access database from javascripting. I could able to read other input values except date and time which were automatically loaded. Its prompting me [object] & [object] for date and time in alert. Please find the below code I used for inserting the html textbox data in the MS-Access DataBase from javascripting. Clicking insert button its giving me error "no value given for one or more required parameters". Could you help me how to read the Date & Time text Boxes input from javascripting.
Code:
<script language="JavaScript">
function insertinto()
{
var globe = null;
globe = new SGWorld();
var xpos = document.all["xcorlon"].value;
alert(xpos);
var ypos = document.all["ycorlat"].value;
alert(ypos);
var zpos = document.all["zcorht"].value;
alert(zpos);
var troupinfon = document.all["trpfile"].value;
alert(troupinfon);
var contree = document.all["country1"].value;
alert(contree);
var trpdate = document.getElementById('date1').value;
alert(date1);
var trptime = document.all["time1"].value;
alert(time1);
var cn = new ActiveXObject("ADODB.Connection");
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = E:\\FramesTemplates\\troupdatabase.mdb;Persist Security Info=False";
cn.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");
var SQL = "insert into troupinf (xcoord,ycoord,zcoord,tropinfor,contry,datetoday,timetoday) values(xpos,ypos,zpos,troupinfon,contree,trpdate,trptime)";
rs.Open(SQL, cn);
alert(rs(0));
rs.Close();
cn.Close();
}
I believe the problem is the SQL statement you're generating:
Code:
var SQL = "insert into troupinf (xcoord,ycoord,zcoord,tropinfor,contry,datetoday,timetoday) values(xpos,ypos,zpos,troupinfon,contree,trpdate,trptime)";
You've hard-coded the variable names, rather than the values. Try something like this:
Yesterday by googling (http://www.webdeveloper.com/forum/ar...hp/t-1957.html) I found the below code and could insert the record in MSAccess DataBase in JavaScript Client side. I will also check with the code given by you.
I'm happy to help, but this is straying into ASP/ADO methods that aren't really relevant in a Javascript forum.
A great resource for help with ADO can be found at W3Schools.com, or in the appropriate forum here.
To get data from the DB into Javascript, the easiest (but least secure) method is to use VB/C# to run the query and output the results of your SELECT query as a global javascript array.
Try something along these lines:
Code:
<%
sql = "SELECT * FROM troupinf"
rs.Open (sql, cn)
results = rs.GetRows()
response.write("<script type='text/javascript'>")
response.write("var a = new Array(" & ubound(results,1) & ");")
for i = 0 to ubound(results,1)
response.write("a[" & i & "] = new Array(" & ubound(results,2) & ");")
for j = 0 to ubound(results,2)
response.write("a[" & i & "][" & j & "]=" & results(i,j) & ";" & vbCrLf)
next
next
response.write("</script>")
%>
Last edited by Alzheimers; 08-13-2009 at 11:23 AM.
Bookmarks