473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Calculated form field numerical amount IF ELSE

MS
Hello,

I have a form with a LoanRequired field which accepts numeric data only.
If user enters >14900 then I want the user to continue as normal with the
default form.
If user enters <1000 then I want a prompt to say "You must apply for at
least £1000"
If user enters between 1000 and 149000 I want to prompt "You must complete
another form" and then redirect to another URL.

Here is my code:
<script>
function calcLoanRequired()
{
if (document.form1.LoanRequired.value > 149000)
{
}
else if (document.form1.LoanRequired.value < 1000)
{
}
else
{
alert("GOING TO OTHER FORM")
document.location.href=("http://lowvalue.co.uk")
}
}
</script>

Now, I get 100 enquiries a day, and although 90 of them go to the right
place, it seems around 10 a day are ignoring the script and the user is able
to submit the form with a value of between 1000 and 149000. The function is
called onBLur (the LoanRequired form field), onClick (The submit button) and
onSubmit(The form tag).

Any ideas?

Thanks!!!

Gary.
PS - I CANNOT REPLICATE THE PROBLEM, I HAVE TRIED EVERYTHING!!!!!

Jul 20 '05 #1
8 1800
On Thu, 22 Jan 2004 19:12:48 GMT, MS <ms@garywhittle.co.uk> wrote:

[snip]
<script>
The type attribute is required for SCRIPT elements. That tag should read:

<script type="text/javascript">

[snip]
Now, I get 100 enquiries a day, and although 90 of them go to the right
place, it seems around 10 a day are ignoring the script and the user is
able to submit the form with a value of between 1000 and 149000. The
function is called onBLur (the LoanRequired form field), onClick (The
submit button) and onSubmit(The form tag).

Any ideas?


Not all users have JavaScript enabled and so your code will have no effect
whatsoever.

ALWAYS validate server-side.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
MS
ALWAYS validate server-side.

Mike

Thanks,

Any pointers on getting started with this? Never tried before.

Gary.
Jul 20 '05 #3
MS
> Not all users have JavaScript enabled and so your code will have no effect
whatsoever.

Hi Mike,

I also collect information about the browser, and whether or not the user
has JavaScript enabled - and even when these things are true, the user still
manages to sometimes get past the script.

Gary.
Jul 20 '05 #4
In article <AP*********************@news-text.cableinet.net>,
ms@garywhittle.co.uk enlightened us with...
ALWAYS validate server-side.

Mike

Thanks,

Any pointers on getting started with this? Never tried before.

Gary.


Where is the form submitting to?
ASP? JSP? Perl? PHP?
--
--
~kaeli~
User: The word computer professionals use when they mean
'idiot'.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #5
On Thu, 22 Jan 2004 21:00:58 GMT, MS <ms@garywhittle.co.uk> wrote:
Not all users have JavaScript enabled and so your code will have no
effect whatsoever.


Hi Mike,

I also collect information about the browser, and whether or not the user
has JavaScript enabled - and even when these things are true, the user
still manages to sometimes get past the script.


The only other possibility that I can think of at the moment is that your
comparisons are at fault. You are comparing a string to a number, and if
the proper type conversion doesn't occur, the comparison might fail.

Try converting the strings to numbers, then compare them to be sure.

function calcLoanRequired() {
// give this a more appropriate name
var number = Number( document.form1.LoanRequired.value );

if ( isNaN( number )) {
// Value entered wasn't actually a number
// Cancel the submission and alert the user
} else {
if ( number > 149000 ) {
} else if ( number < 1000 ) {
} else {
alert("GOING TO OTHER FORM");
document.location.href = "http://lowvalue.co.uk";
}
}
}

It's a shame you can't see a pattern in the erroneous submissions.

Good luck,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #6
MS
> Try converting the strings to numbers, then compare them to be sure.

function calcLoanRequired() {
// give this a more appropriate name
var number = Number( document.form1.LoanRequired.value );

if ( isNaN( number )) {
// Value entered wasn't actually a number
// Cancel the submission and alert the user
} else {
if ( number > 149000 ) {
} else if ( number < 1000 ) {
} else {
alert("GOING TO OTHER FORM");
document.location.href = "http://lowvalue.co.uk";
}
}
}


Hi Mike,

Thanks for the time your spending trying to help me. I have cracked it, its
not the numbers as I have "number only" script on the form field.

Here is what is happening.
When a user hits the submit button and the rate is lower than £149,000 it is
supposed to go to another file. However, it first dsiplays an alert on the
page explaining that a new page is going to be loaded. The onClick
behaviour, has a second function applied to it, which submits the form.
Because of the alert, IE does not actually "appear" to submit the form, even
though it has in fact sent the data. Then, when you press OK on the alert,
the redirection occurs.

Sorted now! :)

Thanks guys,

Gary.
Jul 20 '05 #7
On Thu, 22 Jan 2004 19:12:48 GMT, "MS" <ms@garywhittle.co.uk> wrote:
Hello,

I have a form with a LoanRequired field which accepts numeric data only.
If user enters >14900 then I want the user to continue as normal with the
default form.
If user enters <1000 then I want a prompt to say "You must apply for at
least £1000"
If user enters between 1000 and 149000 I want to prompt "You must complete
another form" and then redirect to another URL.

Here is my code:
<script>
function calcLoanRequired()
{
if (document.form1.LoanRequired.value > 149000)
{
}
else if (document.form1.LoanRequired.value < 1000)
{
}
else
{
alert("GOING TO OTHER FORM")
document.location.href=("http://lowvalue.co.uk")
}
}
</script>

Now, I get 100 enquiries a day, and although 90 of them go to the right
place, it seems around 10 a day are ignoring the script and the user is able
to submit the form with a value of between 1000 and 149000. The function is
called onBLur (the LoanRequired form field), onClick (The submit button) and
onSubmit(The form tag).

Any ideas?

Thanks!!!

Gary.
PS - I CANNOT REPLICATE THE PROBLEM, I HAVE TRIED EVERYTHING!!!!!

Maybe the end users dont have Javascript enabled...

HTH
Al.
Jul 20 '05 #8
JRS: In article <Qg*********************@news-text.cableinet.net>, seen
in news:comp.lang.javascript, MS <ms@garywhittle.co.uk> posted at Thu,
22 Jan 2004 19:12:48 :-
function calcLoanRequired()
{
if (document.form1.LoanRequired.value > 149000)
{
}
else if (document.form1.LoanRequired.value < 1000)
{
}
else
{
alert("GOING TO OTHER FORM")
document.location.href=("http://lowvalue.co.uk")
}
}


Minor point : for efficiency, use

var V = document.form1.LoanRequired.value

and then refer just to V.

You have possible problems other than those in the answers I have seen.

What happens if the string contains £12345 or 12,345 or £12,345 ?
Or even €100000 ? (that's a euro sign). It will, converted to Number,
be NaN, therefore unequal to anything.

You should validate the input with a RegExp to ensure that it contains
only digits, after which you can make V into a number by

var V = + document.form1.LoanRequired.value

which increases efficiency too.

Read the FAQ.

Read <URL:http://www.merlyn.demon.co.uk/js-valid.htm>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Anonymous | last post by:
Hi all, I have a form people use to enter checking data. One of the fields is calculated based on finding the difference of two input fields on the form. Here are the fields: CheckAmount...
14
by: Allen Browne | last post by:
Subform is based on a single-table query that contains a calculated field: Amount: Round(CCur(Nz(*,0)),2) Continuous subform displays this field in a text box named Amount. As user enters new...
1
by: tconway | last post by:
I have an Access program that displays Customer data into a form and OrderID data into a subform. The totals in the Subform are based on calculated fields, i.e. the Total Amount field Calculates...
4
by: Apple | last post by:
Can I edit an calculated field in my form if needed. Thank you in advance for your help. Sincerely Apple
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.