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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing form results

Status
Not open for further replies.

Scarecrow

MIS
Mar 16, 2001
12
0
0
US
I am in the process of creating a fantasy baseball auction page where you bid on the players by offering them contracts of varoius lengths and amounts. The problem I am having is that it doesn't check to see if a persons offer is the best offer. Below is the script I am using:

<FORM NAME=&quot;frmBid&quot; ACTION=&quot;AddBid.asp&quot; METHOD=&quot;POST&quot;
onSubmit=&quot;return VerifyData()&quot;>
<INPUT TYPE=&quot;Hidden&quot; NAME=&quot;ItemID&quot; VALUE=&quot;<%= Request(&quot;Item&quot;) %>&quot;>
<P>
<TABLE WIDTH=&quot;70%&quot; BORDER=&quot;0&quot; CELLPADDING=5>
<TR>
<TD WIDTH=20% ROWSPAN=11> </TD>
<TD WIDTH=20%>Item:</TD>
<TD><%= strItemName %></TD>
</TR>
<TR>
<TD>Description:</TD>
<TD><a target=&quot;_blank&quot; href=&quot;<%= strDescription %>&quot;>Statistics</a></TD>
</TR>
<TR>
<TD>Contract Length:</TD>

<TD><select size=&quot;1&quot; name=&quot;Length&quot;>
<option selected value=&quot;1&quot;>1</option>
<option value=&quot;2&quot;>2</option>
<option value=&quot;3&quot;>3</option>
<option value=&quot;4&quot;>4</option>
<option value=&quot;5&quot;>5</option>
</select></TD>
</TR>
<TR>
<TD>Contract Amt (per yr):</TD><TD><INPUT TYPE=&quot;number&quot; NAME=&quot;Bid&quot; SIZE=&quot;20&quot;></TD>
</TR>
<TR>
<TD></TD>
<TD ALIGN=CENTER COLSPAN=2><BR>
<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Bid on Item&quot;>  
<INPUT TYPE=&quot;RESET&quot;></TD>
</TR>
</TABLE>
</FORM>
<SCRIPT language=&quot;JavaScript&quot;>
<!--
function VerifyData()
{
if ((document.frmBid.Bid.value)*(3-ABS(3-(document.frmBid.Length.value))+5.47)) <= <%= varHighBid %>
{
alert (&quot;I have received a better offer. Please reconsider.&quot;);
return false;
}
else
return true;
}
-->
</SCRIPT>

My questions are:
1. Can this be done without the use of javascript, and,
2. If not, what is wrong with what I have?
 
this line doesn't make much sense
if ((document.frmBid.Bid.value)*(3-ABS(3-(document.frmBid.Length.value))+5.47)) <= <%= varHighBid %>
what is the suedocode for what you are trying to accomplish in this equation?
the last bit deffinetly is in error
<= <%= varHighBid %>
try declaring a javascript variable with this value in it. do this outside the function though.
also is the way you pasted everything the reason the javascript function is below the form. it should be in the head section if it is really formatted this way A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
the original formula used is: Bid*(3-ABS(3-Length))+5.47, where length is the length of the contract, and bid is the amount of the contract. varHighBid is the highest bid amount (using the same formula) in the database.


 
hmm. ok, take a look at this. the logic here is you are jsut comparing a database value and seeing if it is lower then the user input. I think the equation isn't really relavent at this point or maybe I'm wrong. either way all you need to do if plug the equation into what I have done here and it will work also. notice how I declare the value of the DB value outside the function. also, you cannot use Length as it is a predefined word in javascript. hence the changes in the select

<html>
<head>
<SCRIPT language=&quot;JavaScript&quot;>
<!--
var curBid = &quot;100.00&quot;
/*&quot;<%= varHighBid %>&quot;*/

function VerifyData()
{
if ((frmBid.Bid.value)*(frmBid.sel.options[frmBid.sel.selectedIndex].value) < curBid)

{
alert (&quot;I have received a better offer. Please reconsider.&quot;);
frmBid.Bid.focus();
return false;
}
else
{
return true;
}
}
-->
</SCRIPT>
</head>
<body>

<FORM NAME=&quot;frmBid&quot; ACTION=&quot;AddBid.asp&quot; METHOD=&quot;POST&quot; onSubmit=&quot;return VerifyData()&quot;>

<P>
<TABLE WIDTH=&quot;70%&quot; BORDER=&quot;0&quot; CELLPADDING=5>
<TR>
<TD>Contract Length:</TD>
<TD><select size=&quot;1&quot; name=&quot;sel&quot;>
<option selected value=&quot;1&quot;>1</option>
<option value=&quot;2&quot;>2</option>
<option value=&quot;3&quot;>3</option>
<option value=&quot;4&quot;>4</option>
<option value=&quot;5&quot;>5</option>
</select></TD>
</TR>
<TR>
<TD>Contract Amt (per yr):</TD><TD><INPUT TYPE=&quot;number&quot; NAME=&quot;Bid&quot; SIZE=&quot;20&quot;></TD>
</TR>
<TR>
<TD ALIGN=CENTER COLSPAN=2><BR>
<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Bid on Item&quot;>
<INPUT TYPE=&quot;RESET&quot;></TD>
</TR>
</TABLE>
</FORM>
</body>
</html>

A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
here's your equation converted for this instance
syntax
(bid)*(3-Math.abs(3-selected))+5.47)
test
alert(&quot;100.00&quot;*(3-Math.abs(3-1))+5.47);

I had to refresh my Math. syntax and didn't want to post anything bad for you.

hope that helps A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Just so I make sure I understand what you've said, my script should now look like this?:

<SCRIPT language=&quot;JavaScript&quot;>
<!--
var curBid = &quot;<%= varHighBid %>&quot;
function VerifyData()
{
if ((document.frmBid.Bid.value)*(3-Math.abs(3-(frmBid.sel.options[frmBid.Sel.selectedIndex].value)))+5.47) < curBid)
{
alert (&quot;I have received a better offer. Please reconsider.&quot;);
frmBid.Bid.focus();
return false;
}
else
return true;
}
-->
</SCRIPT>

It still isn't working, but I think that's because there is something wrong in the <%= varHighBid %> portion. The guy I'm writing this with is going to check that out.

By the way, thanks for all your help!
 
the way I had it, being the way you changed to ran ok for me. however I substituted the variable of the high bid with a hard coded amount so if it is not working that is the only reasoning behind it I can think of.
try something like this to test the value

<% Response.Write varHighBid %>
<script>
var curBid = &quot;<%= varHighBid %>&quot;
alert(curBid);
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
also try
var curBid = &quot;<%= Response.Write varHighBid %>&quot;
I actually think that would be the correct syntax for giving the javascript variable the value of the ASP var.
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top