Connecting Tech Pros Worldwide Help | Site Map

reject error

  #1  
Old February 9th, 2006, 08:25 PM
Torbjørn Pettersen
Guest
 
Posts: n/a
A form input where value = viagra is to be rejected using a javascript,
but it doesn't work at all.

Line 30 and on is where the last attempt to get the code to work is.
http://html-channel.com/pastebin.php?id=2

Anyone able to help me with this?

--
Torbjørn Pettersen


  #2  
Old February 9th, 2006, 08:35 PM
web.dev
Guest
 
Posts: n/a

re: reject error



Torbjørn Pettersen wrote:[color=blue]
> A form input where value = viagra is to be rejected using a javascript,
> but it doesn't work at all.
>
> Line 30 and on is where the last attempt to get the code to work is.
> http://html-channel.com/pastebin.php?id=2
>
> Anyone able to help me with this?[/color]
[color=blue]
>document.MyForm.Name.value.toLowerCase().equals(' viagra')[/color]

Is there a reason why you can't simply do the following:

document.forms["MyForm"].elements["Name"].toLowerCase() == "viagra"

Because there is no String method "equals".

  #3  
Old February 9th, 2006, 08:45 PM
Torbjørn Pettersen
Guest
 
Posts: n/a

re: reject error


web.dev wrote:[color=blue][color=green]
>> document.MyForm.Name.value.toLowerCase().equals('v iagra')[/color]
>
> Is there a reason why you can't simply do the following:
>
> document.forms["MyForm"].elements["Name"].toLowerCase() == "viagra"
>
> Because there is no String method "equals".[/color]

Didn't work. :-(

--
Torbjørn Pettersen


  #4  
Old February 9th, 2006, 10:15 PM
VK
Guest
 
Posts: n/a

re: reject error



Torbjørn Pettersen wrote:[color=blue]
> web.dev wrote:[color=green][color=darkred]
> >> document.MyForm.Name.value.toLowerCase().equals('v iagra')[/color]
> >
> > Is there a reason why you can't simply do the following:
> >
> > document.forms["MyForm"].elements["Name"].toLowerCase() == "viagra"
> >
> > Because there is no String method "equals".[/color]
>
> Didn't work. :-([/color]

There is not method "equals" in JavaScript String object. Use simple
comparison instead as suggested:

// WRONG:
if (document.MyForm.Name.value.toLowerCase().equals(' viagra'))

// RIGHT:
if (document.MyForm.Name.value.toLowerCase() == 'viagra')

  #5  
Old February 9th, 2006, 10:15 PM
shiva.vannavada@gmail.com
Guest
 
Posts: n/a

re: reject error


Try this:

document.MyForm.Name.value.toLowerCase() == "viagra"

- shiva

Torbjørn Pettersen wrote:[color=blue]
> web.dev wrote:[color=green][color=darkred]
> >> document.MyForm.Name.value.toLowerCase().equals('v iagra')[/color]
> >
> > Is there a reason why you can't simply do the following:
> >
> > document.forms["MyForm"].elements["Name"].toLowerCase() == "viagra"
> >
> > Because there is no String method "equals".[/color]
>
> Didn't work. :-(
>
> --
> Torbjørn Pettersen[/color]

  #6  
Old February 9th, 2006, 10:25 PM
Torbjørn Pettersen
Guest
 
Posts: n/a

re: reject error


VK wrote:[color=blue]
> There is not method "equals" in JavaScript String object. Use simple
> comparison instead as suggested:
>
> // WRONG:
> if (document.MyForm.Name.value.toLowerCase().equals(' viagra'))
>
> // RIGHT:
> if (document.MyForm.Name.value.toLowerCase() == 'viagra')[/color]

Didn't work. No errors, just accepted viagra as input in the name field.

--
Torbjørn Pettersen


  #7  
Old February 9th, 2006, 10:25 PM
Torbjørn Pettersen
Guest
 
Posts: n/a

re: reject error


shiva.vannavada@gmail.com wrote:[color=blue]
> Try this:
>
> document.MyForm.Name.value.toLowerCase() == "viagra"[/color]

Didn't work. No errors, just accepted viagra as input in the name field.

--
Torbjørn Pettersen


  #8  
Old February 9th, 2006, 10:35 PM
VK
Guest
 
Posts: n/a

re: reject error



Torbjørn Pettersen wrote:[color=blue]
> VK wrote:[color=green]
> > There is not method "equals" in JavaScript String object. Use simple
> > comparison instead as suggested:
> >
> > // WRONG:
> > if (document.MyForm.Name.value.toLowerCase().equals(' viagra'))
> >
> > // RIGHT:
> > if (document.MyForm.Name.value.toLowerCase() == 'viagra')[/color]
>
> Didn't work. No errors, just accepted viagra as input in the name field.[/color]

Because you used assignment (=) instead of comparison (==).

Do not retype the code, just copy'n'paste this line:

if (document.MyForm.Name.value.toLowerCase() == 'viagra') {

instead of your current one on the line 31 at
<http://html-channel.com/pastebin.php?id=2>

  #9  
Old February 10th, 2006, 01:05 AM
Stephen Chalmers
Guest
 
Posts: n/a

re: reject error



Torbjørn Pettersen wrote:[color=blue]
> A form input where value = viagra is to be rejected using a javascript,
> but it doesn't work at all.
>
> Line 30 and on is where the last attempt to get the code to work is.
> http://html-channel.com/pastebin.php?id=2
>
> Anyone able to help me with this?
>
> --
> Torbjørn Pettersen[/color]

[color=blue]
> <script type='JavaScript'>[/color]

You get no errors because your code is being ignored quite rightly as
an unknown type.

<script type='text/JavaScript'>
--
S.C.

  #10  
Old February 10th, 2006, 06:25 AM
Torbjørn Pettersen
Guest
 
Posts: n/a

re: reject error


Stephen Chalmers wrote:[color=blue][color=green]
>> <script type='JavaScript'>[/color]
>
> You get no errors because your code is being ignored quite rightly as
> an unknown type.
>
> <script type='text/JavaScript'>[/color]

The rest of the script works fine, and changing as you proposed here
didn't do any good either. Almost starting to think this is not fixable.

--
Torbjørn Pettersen


  #11  
Old February 10th, 2006, 08:55 AM
VK
Guest
 
Posts: n/a

re: reject error



Torbjørn Pettersen wrote:[color=blue]
> Stephen Chalmers wrote:[color=green][color=darkred]
> >> <script type='JavaScript'>[/color]
> >
> > You get no errors because your code is being ignored quite rightly as
> > an unknown type.
> >
> > <script type='text/JavaScript'>[/color]
>
> The rest of the script works fine, and changing as you proposed here
> didn't do any good either. Almost starting to think this is not fixable.[/color]

You still have nothing changed: still non-existing equals() method,
still non-existing text/JavaScript content type. Please post or link
the *current last modified* variant you are having problems with.

Please remove all ASP tags as irrelevant: it is indeed difficult to
sort out. The simpliest way is to open your page in the browser, View >
Page Source, copy'n'paste.

We are willing to help, but please help us either.

  #12  
Old February 10th, 2006, 03:05 PM
Torbjørn Pettersen
Guest
 
Posts: n/a

re: reject error


VK wrote:[color=blue]
> You still have nothing changed: still non-existing equals() method,
> still non-existing text/JavaScript content type. Please post or link
> the *current last modified* variant you are having problems with.
>
> Please remove all ASP tags as irrelevant: it is indeed difficult to
> sort out. The simpliest way is to open your page in the browser, View[color=green]
> > Page Source, copy'n'paste.[/color]
>
> We are willing to help, but please help us either.[/color]

Sorry, getting a bit frustrated. Have of course changed the code,
will post link to fresh code as I do changes from now on.

http://html-channel.com/pastebin.php?id=5 is the current last mod
the javascript of the page only.

http://html-channel.com/pastebin.php?id=6 is with html/asp included.

As you see there are two javascripts, the first one nothing works in. :-)
Not even if I don't enter any values into the form. :-/

The second is the one that checks for too long words, which works like
a charm. (Starts on line 69)

I'm no js coder myself, and this is just tweaking code done for
me by a friend who is no longer here to help me. I do understand
what the purpose of the code is, and the piece of code that is to
reject viagra as a input is placed there by me. :-)

--
Torbjørn Pettersen


  #13  
Old February 10th, 2006, 08:05 PM
Stephen Chalmers
Guest
 
Posts: n/a

re: reject error



Torbjørn Pettersen wrote:[color=blue]
>
> http://html-channel.com/pastebin.php?id=6 is with html/asp included.
>[/color]

If you are getting no errors it can be only because you have disabled
error reporting in your browser, or it does not pop-up the JS console
on error (Mozilla/Firefox).

[color=blue]
>if {document.MyForm.Name.value.toLowerCase == "viagra"}[/color]

should be:

if (document.MyForm.Name.value.toLowerCase() == "viagra")

There are also some errors in the if-else constructs, which the JS
console will specify.

--
S.C.


--
S.C.

  #14  
Old February 16th, 2006, 03:45 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: reject error


Torbjørn Pettersen wrote:
[color=blue]
> shiva.vannavada@gmail.com wrote:[color=green]
>> Try this:
>>
>> document.MyForm.Name.value.toLowerCase() == "viagra"[/color]
>
> Didn't work. No errors, just accepted viagra as input in the name field.[/color]

You should not name a form control `name' because that is the name of a
property of HTMLFormElement objects already. Furthermore, standards
compliant syntax is

document.forms['MyForm'].elements['nameOfYourControl'].value.toLowerCase()
== "viagra"

You want to consider

var e = document.forms['MyForm'].elements['nameOfYourControl'];

// matches "viagra" case-insensitive anywhere in the value
... e.value.test(/viagra/i) ...

// or, for a strict case-insensitive match

... e.value.test(/^viagra$/i) ...

See also previous discussions about form validation; they contain
descriptions of more efficient and less error-prone property accesses.


PointedEars
  #15  
Old February 16th, 2006, 03:55 PM
Evertjan.
Guest
 
Posts: n/a

re: reject error


Thomas 'PointedEars' Lahn wrote on 16 feb 2006 in comp.lang.javascript:
[color=blue]
> document.forms['MyForm'].elements['nameOfYourControl'].value.toLowerCa
> se() == "viagra"[/color]

In your case, to keep you in your form, is that what you are controlled by?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
elegant error handling in message processors, how? petschy answers 2 November 13th, 2006 06:55 PM
How to intercept error when httpRuntime maxRequestLength is exceded. moondaddy answers 25 November 18th, 2005 06:01 PM
XMLSerializer error Mark Oliver answers 0 November 16th, 2005 04:19 AM
Valid answer 1-10 only. All else gets error message. jel answers 1 July 22nd, 2005 04:27 AM