Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Handle Form Data in Javascript
Old 05-22-2004, 12:27 PM Handle Form Data in Javascript
Zork's Avatar
Extreme Talker

Posts: 201
Trades: 0
I have a form
<form name="info" action="buyaa.asp">
<input type="text" name="mymoney">
<input type="text" name="price">
</form>

And I want to use javascript to take in the form data and compare it:

var mymoney = (this.. I guess. is were the value for mymoney on the last page would go)
var price = (same as above)
if mymoney<price then
{
blah
}
else
{
blah
}

How would I go about doing this?

Thanks in advance
__________________
"Computer games don't affect kids. I mean, if Pacman affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music..."
Zork is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-22-2004, 01:06 PM
Extreme Talker

Posts: 160
Trades: 0
I hope the following code helps. The form will only be submitted to the asp script if the value of mymoney is greater than or equal to the price.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Validate form</title>
<script language="JavaScript" type="text/javascript">
<!--
function validate()
{
if(document.info.mymoney.value < document.info.price.value)
{
alert("Sorry, you have insufficient funds");
return false;
}
else {return true;}
}
//-->
</script>
</head>
<body>
<form onSubmit="return validate()" name="info" action="buyaa.asp">
<table>
<tr><td>Funds</td><td><input type="text" name="mymoney"></td></tr>
<tr><td>Price</td><td><input type="text" name="price"></td></tr>
<tr><td colspan="2"><input type="submit" value="Make Purchase"></td></tr>
</table>
</form>
</body>
</html>

HTH
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 05-22-2004, 01:15 PM
Zork's Avatar
Extreme Talker

Posts: 201
Trades: 0
Thanks...

Your script works when not using ASP to insert data into the textboxes, but when I do everything seems backward or just wrong. According to the script, it said 2121212 was less then 300 but great then 500. What could be going wrong here?

After doing some testing, it doesn't work if I have asp insert the value of the textbox. any alternatives?

Thanks for the help,
__________________
"Computer games don't affect kids. I mean, if Pacman affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music..."

Last edited by Zork; 05-22-2004 at 02:52 PM.. Reason: Stopped working
Zork is offline
Reply With Quote
View Public Profile
 
Old 05-22-2004, 01:22 PM
Zork's Avatar
Extreme Talker

Posts: 201
Trades: 0
__________________
"Computer games don't affect kids. I mean, if Pacman affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music..."

Last edited by Zork; 05-22-2004 at 02:34 PM..
Zork is offline
Reply With Quote
View Public Profile
 
Old 05-23-2004, 02:26 PM
Extreme Talker

Posts: 160
Trades: 0
I think it may be a data type problem. Amend the condition as follows using the parseFloat method. Let me know how you get on.

if(parseFloat(document.info.mymoney.value)<parseFl oat(document.info.price.value))

HTH
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Handle Form Data in Javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26374 seconds with 12 queries