Click to See Complete Forum and Search --> : Problem!!!


petermar30030
06-26-2003, 10:39 AM
I'm Trying To Make A Function That Will Check If You Have A

Value More Than a Certain Number You'll Get a Pop-up Saying,
"You Don't Have Enough To Enter That Much Right Now!".

But When I Check My Function, Which goes something like

This...
<html>
<script language='javascript' type=text/javascript'>
<!-- Begin
function Take_value()
{
Value = document.Form1.Text1.value;
if (value >= '1000')
alert('You Don't Have Enough To Enter That Much Right Now!');
else
alert('You Took Out ' + Value);
}
end -->
</script>
<form name=Form1>
<input type='text' name='Text1'>
<input type='BUTTON' value='Submit' onClick=Take_value()>
</html>

It Says You Dont Have Enough To Enter That Much Right now!

When I Enter 200.

Can Anyone Out There Help Me? If You Can Please Show Me

a Example Script That Might Work For Me...

Richard1
06-26-2003, 10:55 AM
Here is a script that you may be able to manipulate.

http://javascript.internet.com/forms/val-num-or-char.html

If this is not what you are looking for, look around the site and I'm sure you'll find something!

http://javascript.internet.com

Hope this helps!

SlankenOgen
06-26-2003, 11:52 AM
Value = document.Form1.Text1.value;
if (value >= '1000')

Value should have a capital V in both cases.

~mgb

pyro
06-26-2003, 11:57 AM
Originally posted by SlankenOgen
Value = document.Form1.Text1.value;
if (value >= '1000')

Value should have a capital V in both cases.

~mgb Or, if you want to follow common coding practices, make them both lowercase, instead.

petermar30030
06-26-2003, 12:09 PM
I Already Tried That But When I Type In 20 It Gives The Alert Message Saying 'You Don't have enough.:cool:

pyro
06-26-2003, 12:10 PM
Are you trying to validate the length of the message? If so, I think this is what you are looking for:

value = document.Form1.Text1.length;

Vladdy
06-26-2003, 12:15 PM
You are comparing string to a string:
if (value >= '1000')

when you should be comparing number to a number:
if(parseInt(value) >= 1000)

SlankenOgen
06-26-2003, 12:18 PM
Best to get rid of the word value altogether. I NEVER use nothin that remotely resembles a keyword or even a html tag. It's just asking for trouble. Use a word like 'money' or something that is positively neutral.

~mgb

petermar30030
06-26-2003, 12:26 PM
I Don't Think I Made My Problem Clear Enough,
My Problem Is That When I Type In A Number Such as 20 Or 200 When The Allowed Value is 1000 Then I Get That Message saying you dont have enough.
I Think The Problem Is that The First Number Of What I Typed In Was 2 When The Function's First Number Is 1, Maby Now You Can Help Me a little Better.:cool:

SlankenOgen
06-26-2003, 12:36 PM
This works-

<html>
<script type = "text/javascript">

var money = 0;

function Take_value()
{
money = document.Form1.Text1.value;
if (money >= 1000)
{
alert("You Don't Have Enough To Enter That Much Right Now!");
}
else
{
alert("You Took Out" + money);
}
}

</script>
</head>
<body>
<form name="Form1">
<input type="text" name="Text1">
<input type="BUTTON" value="Submit" onClick="Take_value()">
</form>
</body>
</html>

You should declare the existence of the money/Value variable then give it a value.
~mgb

SlankenOgen
06-26-2003, 12:46 PM
For the sake of completeness...

<html>
<script type = "text/javascript">

var money = 0;

function Take_value()
{
money = document.Form1.Text1.value;
if(isNaN(money) || money == "")
{
alert("Please enter a numerical amount.");
document.Form1.Text1.value = "";
document.Form1.Text1.focus();
return;
}
if (money >= 1000)
{
alert("You Don't Have Enough To Enter That Much Right Now!");
}
else
{
alert("You Took Out" + money);
}
}

</script>
</head>
<body>
<form name="Form1">
<input type="text" name="Text1">
<input type="BUTTON" value="Submit" onClick=Take_value()>
</form>
</body>
</html>

~mgb

petermar30030
06-26-2003, 12:49 PM
-SlankenOgen
That Worked Preety Well But Do You Think You Can Make A Function That Would Store the money...
I Already Have One But it's fairly Long and mabey you could create a script that smaller than one-hundred lines.
Thanks in Advance :cool:

SlankenOgen
06-26-2003, 12:54 PM
var moneyStore = new Array();

var cntr = -1;

function Take_value(){
.
.
.else
{
alert("You Took Out" + money);
moneyStore[++cntr] = money;
}
.
.
.
}

This will store the money values in an array. Use window.alert(moneyStore);

to check it.

~mgb

petermar30030
06-26-2003, 12:59 PM
Thanks!
You Helped Me Out Alot!

SlankenOgen
06-26-2003, 01:02 PM
You're welcome.

~mgb

petermar30030
06-26-2003, 02:12 PM
Do You Think You Can Put That All Together So That When I Run It Will Do All Of This , If You Do Please Include A 'How Much Do I Have Lef Button Showing Me How Much I can Put in The Box.