How can retrieve data from Access by using forms?
Hi,
I am trying to get some values retrieved from an Access database by using the radio and checkboxes form elements. These valued should be summed up as soon as any changes are made to the form by an onclick event handler.
In total I have three pages but the first one ("default.asp") only consists of a frameset (so there is no problem). The two other pages ("main.asp") and ("sum.asp") are where I have problems. Particularly I feel I have problems with the ("sum.asp"), and maybe some minor with the "main.asp".
Inside the "sum.asp" I have written some additional clarifications. I guess I need some kind of SQL code to get it right....
Hope to get some assistance...
URL âdefault.aspâ
<FRAMESET ROWS="*,100">
<FRAME NAME="main" src="main.aspâ Scrolling="auto">
<FRAME NAME="sum" src=âsum.aspâ Scrolling="no">
</FRAMESET>
URL âmain.aspâ
<html>
<head>
<title>
I canât figure it out, please help meâ¦.
</title>
<Script language="JavaScript">
function update(formobject)
{
document.form1.submit();
}
</Script>
</head>
<body>
Time for a very basic lesson in mathematicsâ¦
<form action="sum.asp" method= "post" name="form1">
<input type="radio" name="radio1" value="10" OnClick="update()" checked> <br>
<input type="radio" name="radio1" value="11" OnClick="update()"> +5 <br>
<input type="radio" name="radio2" value="20" OnClick=" update()" checked> <br>
<input type="radio" name="radio2" value="21" OnClick=" update()"> -5 <br>
<input type="checkbox" name="check3" value="30" OnClick=" update(this.form)" checked> <br>
<input type="checkbox" name="check4" value="40" OnClick=" update(this.form)"> +5 <br>
</form>
</body>
</html>
URL âsum.aspâ
<html>
<head>
<title>
The total sum from the checked elements in the form should be displayed here
</title>
</head>
<body>
<%radio1 = request.form1("radio1")%>
<%radio2 = request.form1("radio2")%>
<%check3 = request.form1("check3")%>
<%check4 = request.form1("check4")%>
// Unless I am wrong the values from the selected elements in the form should now be retrieved and stored in the 4 different variables above. Now I wonder how I can retrieve some prices from an Access database named âproductsâ and a column named âpriceâ for each of the above mentioned variables. In the database there is also a column named âproduct IDâ (that corresponds to the values stored in the variables above and therefore should be used to identify each record). I want the 2 (depending on the checkboxes) or 4 prices added to a variable named âsumâ. As you can se below I want the âsumâ variable to be displayed to the user. Since I have an âonclickâ-event on the âmain.aspâ URL I want the âsumâ variable to be updated as soon any change is made in the form. The default value of âsumâ should be 30 since the checked form elementsâ prices are 10 each (if they are retrieved correctly from the database) :). //
The sum of the chosen radio buttons and checkboxes is:
<%
Response.Write sum
%>
</body>
</html>
|