Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function not being entered.

Status
Not open for further replies.

brodemeyer

Programmer
Oct 10, 2006
4
US
I have an asp page that is basically suppose to work like eBay where the user enters a bid and their name. The asp page is calling a javascript function. The page works fine meaning the user can bid on an item and the database is updated however I am trying to validate the bid as to that it is at least $1.00 above the current bid. Right now I have placed a window.alert message at the top of the function and it is not appearing so the function is not being entered at all. Looking at the code below can anyone see anything wrong? I am a beginner so I apologize if the code is sloppy, any suggestions is appreciated. Thanks.

Here is the code:

<html>
<head>
<title>United Way Bank-Bay</title>

</head>

<body><%
Session.timeout = 5
If IsObject(Session("Auction_conn")) Then
Set conn = Session("Auction_conn")
Else
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Auction"
Set Session("Auction_conn") = conn
End If
%>
<%
If IsObject(Session("Auction_rs")) Then
Set rs = conn.Execute("SELECT * FROM Auction WHERE ItemName = 'Notebook'")
'Set rs = Session("Auction_rs")
Else
sql = "SELECT * FROM Auction WHERE ItemName = 'Notebook'"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn, 3, 3
If rs.eof Then
rs.AddNew
End If
Set Session("Auction_rs") = rs
End If
%>

<script type="jscript">
function validate()
{
window.alert("In Function!");
if(<%=Server.HTMLEncode(rs.Fields("HighBid").Value)%> < document.Form1.NewHighBid.value)
{
window.alert("Please enter a value greater than the current bid.");
document.Form1.NewHighBid.focus();
return false;
}
if(document.Form1.NewHighBidder.value == "")
{
window.alert("Please enter your name.");
document.Form1.NewHighBidder.focus();
return false;
}
}
</script>

<table style="WIDTH: 769px; HEIGHT: 72px">
<link rel="STYLESHEET" type="text/css" href="../dhtmlcentral.css">
<script language="JavaScript1.2" src="../coolmenus4.js">
</script>

<tr align="left">

<td height="65" background="../images/topbar.bmp"><FONT
size=6>

</FONT>
<A href=" height=39 alt="" src="../images/home.bmp" width=80 border=0></A></td>
</tr>
</table>
<table style="WIDTH: 769px; HEIGHT: 356px">
<tr><!--Left Side-->
<td width="22%" height="350" align="middle" valign="top" bgcolor="aac6e1"></td><!--Text Area-->
<td width="565" height="350" valign="top"><BR>
<br><!--Start Typing Here-->

<form name="Form1" onSubmit="return validate();" ACTION="update.asp" METHOD="POST">
<div align="left"><p>Welcome. Please place a bid on the item below.<br>
</p>
</div><blockquote>
<div align="center"><div align="center"><center><table border="1" width="512" height="78">
<%
On Error Resume Next
rs.MoveFirst
do while Not rs.eof
%>
<tr>
<td width="83" height="7">Item Name</td>
<td width="417" height="7"><%=Server.HTMLEncode(rs.Fields("ItemName").Value)
%></td>
</tr>
<tr>
<td width="83" height="7">Donator(s)</td>
<td width="417" height="7"><%=Server.HTMLEncode(rs.Fields("Donator").Value)%></td>
</tr>
<tr>
<td width="83" height="7">Current High Bid</td>
<td width="417" height="7"><%=Server.HTMLEncode(rs.Fields("HighBid").Value)%></td>
</tr>
<tr>
<td width="83" height="7">Current High Bidder</td>
<td width="417" height="7"><%=Server.HTMLEncode(rs.Fields("HighBidder").Value)%></td>
</tr>
<tr>
<td width="83" height="7">Your High Bid</td>
<td width="417" height="7"><input type="text" name="NewHighBid" size="20"></td>
</tr>
<tr>
<td width="83" height="7">Your Name</td>
<td width="417" height="7"><input type="text" name="NewHighBidder" size="20"></td>
</tr>

<input type="hidden" name="ItemName" value="Notebook">
<%
rs.MoveNext
loop%>
</table>
</center></div><div align="center"><center><table>
<tr>
<td><div align="center"><center><p><input TYPE="SUBMIT" VALUE="Update"></td>
</tr>
</table>
</center></div></div>
</blockquote>
</form>


</P></table><!--Don't Type Past Here-->
</td>
</tr>
</table>

</body>
</html>
 
I think you need to change
Code:
<input TYPE="SUBMIT" VALUE="Update">
to
Code:
<input TYPE="SUBMIT" VALUE="Update" onClick="validate()">
 
The function call is in the proper place.

Try removing window. from the alerts and see what happens.

Also, you're asking for trouble with no error checking in the NewHighBid text input. What happens if someone enters a space or other non-numeric value? You should probably at least convert the text input value with parseFloat() before comparing it to the bid value written to the page dynamically.

If all else fails, how about showing us your HTML source after the server has processed your ASP code?

Lee
 
Thank you trollacious for your input, I tried your suggestion and it still did not enter the function at all. I will be adding additional error handling later once I get it to enter the function so I thank you for your suggestion.

Listed above is pretty much all of the code with the exception of the update.asp page which is the action for the form and all that code does is update the database but I will paste it below:

<%
<!--#include file="adovbs.inc"-->
TEMP = Request.form("ItemName")


Set DataConn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
DataConn.Open "Auction"

' Note: To keep the example simple I update ALL RECORDS with the name that
' is entered in the text box. This is OK for this example since you will not
' (?) allow duplicates. In the real world you would assign a unique ID# to
' each record (access can do this for you).
Set rsInfo = DataConn.Execute("SELECT * FROM Auction WHERE ItemName = '" & TEMP & "'")

If rsInfo.EOF Then

SQL = "INSERT INTO Auction"
SQL = SQL + " (ItemName, HighBid, HighBidder) VALUES ('" & Request("ItemName") & "', '" & Request("HighBid") & "', '" & Request.Form("HighBidder") & "');"
Set rsInfo = DataConn.Execute(SQL)

Response.Write "<CENTER>Record Updated!<br>"

Else
SQL = "UPDATE Auction"
SQL = SQL + " SET ItemName = '" & Request("ItemName") & "', HighBid= '" & Request("NewHighBid") & "', HighBidder= '" & Request.Form("NewHighBidder") & "'"
SQL = SQL + " WHERE ItemName = '" & TEMP & "';"
Set rsInfo = DataConn.Execute(SQL)

' RS.Close
DataConn.Close

Response.Write "<CENTER>Your bid has been accepted. Remember to keep checking back to make sure you aren't outbid.<br>Bidding ends on November 7th at 4:00 PM.<br><a href=' Here </a>to go back to the list of items up for auction.</CENTER>"
End If

%>
 
Where's the final HTML? Don't post your server-side code, your problem is with the client-side code. When you test the page, click on View -> Source, and copy and paste THAT code in here. That's what the client's browser will see, and we need to see that source to figure out the problem.

Lee
 
Sorry I misunderstood, the code I posted at the beginning is the client code.
 
Sorry I misunderstood, the code I posted at the beginning is the client code.
No it's not. If there are ASP tags in it, it's not client-side code. If you're seeing that in your browser, it's not being processed by IIS, and that could be the problem.

Lee
 
<html>
<head>
<title>United Way Bank-Bay</title>

</head>

<body>

<script type="jscript">
function validate()
{
alert("In Function!");
if(2.25 < document.Form1.NewHighBid.value)
{
alert("Please enter a value greater than the current bid.");
document.Form1.NewHighBid.focus();
return false;
}
if(document.Form1.NewHighBidder.value == "")
{
alert("Please enter your name.");
document.Form1.NewHighBidder.focus();
return false;
}
}
</script>

<table style="WIDTH: 769px; HEIGHT: 72px">
<link rel="STYLESHEET" type="text/css" href="../dhtmlcentral.css">
<script language="JavaScript1.2" src="../coolmenus4.js">
</script>

<tr align="left">

<td height="65" background="../images/topbar.bmp"><FONT
size=6>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</FONT>
<A href=" height=39 alt="" src="../images/home.bmp" width=80 border=0></A></td>
</tr>
</table>
<table style="WIDTH: 769px; HEIGHT: 356px">
<tr><!--Left Side-->
<td width="22%" height="350" align="middle" valign="top" bgcolor="aac6e1"></td><!--Text Area-->
<td width="565" height="350" valign="top"><BR>
<br><!--Start Typing Here-->

<form name="Form1" onSubmit="return validate();" ACTION="update.asp" METHOD="POST">
<div align="left"><p>Welcome. Please place a bid on the item below.<br>
</p>
</div><blockquote>
<div align="center"><div align="center"><center><table border="1" width="512" height="78">

<tr>
<td width="83" height="7">Item Name</td>
<td width="417" height="7">Notebook</td>
</tr>
<tr>
<td width="83" height="7">Donator(s)</td>
<td width="417" height="7">Blake Rodemeyer</td>
</tr>
<tr>
<td width="83" height="7">Current High Bid</td>
<td width="417" height="7">2.25</td>
</tr>
<tr>
<td width="83" height="7">Current High Bidder</td>
<td width="417" height="7">Blake Rodemeyer</td>
</tr>
<tr>
<td width="83" height="7">Your High Bid</td>
<td width="417" height="7"><input type="text" name="NewHighBid" size="20"></td>
</tr>
<tr>
<td width="83" height="7">Your Name</td>
<td width="417" height="7"><input type="text" name="NewHighBidder" size="20"></td>
</tr>

<input type="hidden" name="ItemName" value="Notebook">

</table>
</center></div><div align="center"><center><table>
<tr>
<td><div align="center"><center><p><input TYPE="SUBMIT" VALUE="Update"></td>
</tr>
</table>
</center></div></div>
</blockquote>
</form>


</P></table><!--Don't Type Past Here-->
</td>
</tr>
</table>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top