Connecting Tech Pros Worldwide Help | Site Map

reject error

Torbjørn Pettersen
Guest
 
Posts: n/a
#1: Feb 9 '06
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


web.dev
Guest
 
Posts: n/a
#2: Feb 9 '06

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".

Torbjørn Pettersen
Guest
 
Posts: n/a
#3: Feb 9 '06

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


VK
Guest
 
Posts: n/a
#4: Feb 9 '06

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')

shiva.vannavada@gmail.com
Guest
 
Posts: n/a
#5: Feb 9 '06

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]

Torbjørn Pettersen
Guest
 
Posts: n/a
#6: Feb 9 '06

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


Torbjørn Pettersen
Guest
 
Posts: n/a
#7: Feb 9 '06

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


VK
Guest
 
Posts: n/a
#8: Feb 9 '06

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>

Stephen Chalmers
Guest
 
Posts: n/a
#9: Feb 10 '06

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.

Torbjørn Pettersen
Guest
 
Posts: n/a
#10: Feb 10 '06

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


VK
Guest
 
Posts: n/a
#11: Feb 10 '06

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.

Torbjørn Pettersen
Guest
 
Posts: n/a
#12: Feb 10 '06

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


Stephen Chalmers
Guest
 
Posts: n/a
#13: Feb 10 '06

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.

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#14: Feb 16 '06

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
Evertjan.
Guest
 
Posts: n/a
#15: Feb 16 '06

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