[Javascript] wanted-a database script

uplate at attbi.com uplate at attbi.com
Thu May 1 08:22:06 CDT 2003


Here's a VERY basic way to attempt what you want.
It could certainly stand a great deal of modification
Filin either of the text boxes or none and press the button.
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript1.4">
<!--
	function displaySQL()
	{
		var SQL = new String();
		var where = new String();
		SQL = "SELECT * FROM CUSTOMERS ";
		for (i=0;i<document.form1.elements.length;i++)
		{
			if(document.form1.elements[i].type =="text" && 
document.form1.elements[i].value.length > 0)
			{
			where = where + document.form1.elements[i].name + " = " 
+ document.form1.elements[i].value + " and ";
			}
		}
		if (where.length > 0)
		{
			//Trim appended AND from where string
			where = where.slice(0,where.length -5);
			
			SQL = SQL + " WHERE " + where;
		
		}
		alert(SQL);
	}	
//-->
</script> 
</head>

<body>
<form name="form1" method="post" action="">
<input name="FIRST_NAME" type="text" id="FIRST_NAME">
<input name="LAST_NAME" type="text" id="LAST_NAME">
<input type="button" name="Submit" value="Submit" onClick="displaySQL()">
</form>
</body>
</html>
> I need a javascript script that will take user-entered fields from a HTML
> form and use these to build a SQL 'select' statement.  The script will
> then open and connect to my Microsoft Access table on our site and
> displaying the results set, looping throught each one starting at the 1st
> one and going until it hits EOF. 
> 
> I've searched and searched on the web for just this - a HTML form and a
> javascript script.  Nothing.  So would someone take pity on me and email
> to me the code for the HTML form and a javascript to go with it.  I can
> edit it when I get it. 
> 
> Thank you very much.
> 
> Edwin
> ak429 at chebucto.ns.ca
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list