Hi!
I've got problem.
Everything works fine when on line !1! is just single entry in if
statement. Why after putting "&&" script doesn't work?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
function checkAns( form )
{
var radiock;
for(var i = 0; i < form.radio1.length; i++)
{
if( form.radio1[i].checked )
{
radiock = form.radio1[i].value;
}
}
if( (form.forename.value == "") && (radiock == null) ) /* !1! */
{
alert("please answer all compulsory questions!");
return false;
}
else
{
return true;
}
}
</script>
</HEAD>
<BODY>
<form name="myform" method="get" onsubmit="return checkAns(this);">
<P>
Input your name(compulsory): <input type="text" size="40"
name="forename">
<br>
<br>
fav colour(compulsory)?
<br>
<INPUT TYPE="radio" NAME="radio1" VALUE="red">red</P>
<P>
<INPUT TYPE="radio" NAME="radio1" VALUE="blue">blue</P>
<P>
<INPUT TYPE="radio" NAME="radio1" VALUE="green">green</P>
<P>
<INPUT TYPE="radio" NAME="radio1" VALUE="white">white</P>
<P>
marital status <INPUT TYPE="checkbox" name="marital" value=""></P>
<P>
any other comments <TEXTAREA NAME="comment" ROWS="5" COLS="15"
WRAP="physical"></TEXTAREA>
</P>
<P>
<INPUT TYPE="submit" NAME="NAME" VALUE="submit" ID="Submit1">
</P>
</BODY>
</HTML>
any ideas?
--
Bremse 11 1371
hey, look down for my solution...
"Bremse" <br*************@wp.pl> wrote in message
news:l0********************************@4ax.com... Hi! I've got problem. Everything works fine when on line !1! is just single entry in if statement. Why after putting "&&" script doesn't work?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD>
function checkAns( form ) { var radiock; for(var i = 0; i < form.radio1.length; i++) { if( form.radio1[i].checked ) { radiock = form.radio1[i].value; } } if( (form.forename.value == "") && (radiock == null) ) /* !1! */
Here you want to use || rather than && or the form can be submitted with an
empty name if a colour has been chosen
{ alert("please answer all compulsory questions!"); return false; } else { return true; } } </script>
</HEAD> <BODY> <form name="myform" method="get" onsubmit="return checkAns(this);">
rather than sending 'this', send 'myform'.
<P> Input your name(compulsory): <input type="text" size="40" name="forename"> <br> <br> fav colour(compulsory)? <br> <INPUT TYPE="radio" NAME="radio1" VALUE="red">red</P> <P> <INPUT TYPE="radio" NAME="radio1" VALUE="blue">blue</P> <P> <INPUT TYPE="radio" NAME="radio1" VALUE="green">green</P> <P> <INPUT TYPE="radio" NAME="radio1" VALUE="white">white</P> <P> marital status <INPUT TYPE="checkbox" name="marital" value=""></P> <P> any other comments <TEXTAREA NAME="comment" ROWS="5" COLS="15" WRAP="physical"></TEXTAREA> </P> <P> <INPUT TYPE="submit" NAME="NAME" VALUE="submit" ID="Submit1"> </P> </BODY> </HTML>
any ideas?
-- Bremse
Hope that solves your problem!
Phil
Bremse wrote:
[...] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD>
A title is required, may as well put it here...
<title>Bremse's Form</title>
And for a script to work, you must tell the browser it's a script...
<script type="text/javascript"> function checkAns( form ) { var radiock;
var radiock = null;
for(var i = 0; i < form.radio1.length; i++) { if( form.radio1[i].checked ) { radiock = form.radio1[i].value; } } if( (form.forename.value == "") && (radiock == null) ) /* !1! */
The extra brackets aren't needed
if(form.forename.value == "" && radiock == null) /* !1! */
The above will submit the form if either "forename" has a value or any
radio button has been selected. It will only fail if both the value is
"" *and* no radio button has been checked, it should be:
if(form.forename.value == "" || radiock == null) /* !1! */
If you are going to evaluate whether radiock is "null", then set it to
null when you declare it. It is actually undefined, but if left
unaltered, the expression will return true as you expect, but just in
case...
{ alert("please answer all compulsory questions!"); return false; }
I the following is superfluous, if the function completes happily
it will return true anyway.
else { return true; } } </script>
</HEAD> <BODY> <form name="myform" method="get" onsubmit="return checkAns(this);">
forms also must have an action, even if it's ""
<input .... action="">
<P> Input your name(compulsory): <input type="text" size="40" name="forename"> <br> <br> fav colour(compulsory)? <br> <INPUT TYPE="radio" NAME="radio1" VALUE="red">red</P> <P> <INPUT TYPE="radio" NAME="radio1" VALUE="blue">blue</P> <P> <INPUT TYPE="radio" NAME="radio1" VALUE="green">green</P> <P> <INPUT TYPE="radio" NAME="radio1" VALUE="white">white</P> <P> marital status <INPUT TYPE="checkbox" name="marital" value=""></P> <P> any other comments <TEXTAREA NAME="comment" ROWS="5" COLS="15" WRAP="physical"></TEXTAREA> </P> <P> <INPUT TYPE="submit" NAME="NAME" VALUE="submit" ID="Submit1"> </P>
It's good to let the browser know when the form is finished... but
first add a reset button so it's easy for a user to clear the form.
<input type="reset">
</form>
</BODY> </HTML>
Have fun...
--
Fred
Fred Oz wrote:
[...] I the following is superfluous, if the function completes happily it will return true anyway.
That should have been:
The following else is superfluous... else { return true; }
[...] forms also must have an action, even if it's ""
<input .... action="">
and that should have been:
<form .... action="">
The joys of imperfection.
--
Fred
On Fri, 26 Nov 2004 10:14:54 +0000 (UTC), Phillip Parr <no@no.com> wrote: "Bremse" <br*************@wp.pl> wrote in message news:l0********************************@4ax.com...
<form name="myform" method="get" onsubmit="return checkAns(this);">
rather than sending 'this', send 'myform'.
The OP is correct here. When used in an intrinsic event, the this operator
refers to the element. That particular code is equivalent to
return checkAns(document.forms['myform']);
By the way, replacing either with
return checkAns(myform);
is unreliable and should definitely be avoided.
[snip]
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
(...) Have fun...
thx :-)
--
Bremse
>>> <form name="myform" method="get" onsubmit="return checkAns(this);"> rather than sending 'this', send 'myform'.
The OP is correct here. When used in an intrinsic event, the this operator refers to the element. That particular code is equivalent to
return checkAns(document.forms['myform']);
By the way, replacing either with
return checkAns(myform);
is unreliable and should definitely be avoided.
Ok, I will change it :-)
--
cheers
Bremse
On Fri, 26 Nov 2004 20:53:09 +1000, Fred Oz <oz****@iinet.net.auau> wrote:
[snip] The extra brackets aren't needed
if(form.forename.value == "" && radiock == null) /* !1! */
True, but parentheses are good for readability, as much as determining
precedence.
[snip]
if(form.forename.value == "" || radiock == null) /* !1! */
Which could be reduced further to
if(!form.forename.value || !radiock)
If you are going to evaluate whether radiock is "null", then set it to null when you declare it. It is actually undefined, but if left unaltered, the expression will return true as you expect, but just in case...
I would only expect such a comparison to fail with a broken ECMAScript
implementation. The equality algorithm equates undefined and null. Only a
strict equality (===) comparison should evaluate to false.
[snip]
I the following is superfluous, if the function completes happily it will return true anyway.
A function that exits without any return statement, or with
return;
will return undefined, not true. However, only
return false;
will cancel an event so returning true or undefined is pretty much
equivalent.
[snip]
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
On Fri, 26 Nov 2004 11:29:41 +0000, Bremse <br*************@wp.pl> wrote:
[snip] Ok, I will change it :-)
Ack!! What?
No, *don't* change it. You were right in the first place: use the this
operator!
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
While you say the this operator was correct, you don't explain why his
script didn't work. Indeed, I didn't get it to work with 'this' either.
Phil
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsh2ldbfxx13kvk@atlantis... On Fri, 26 Nov 2004 11:29:41 +0000, Bremse <br*************@wp.pl> wrote:
[snip]
Ok, I will change it :-)
Ack!! What?
No, *don't* change it. You were right in the first place: use the this operator!
Mike
-- Michael Winter Replace ".invalid" with ".uk" to reply by e-mail.
On Fri, 26 Nov 2004 12:03:47 +0000 (UTC), Phillip Parr <no@no.com> wrote: While you say the this operator was correct, you don't explain why his script didn't work.
Because I assume that Fred's more comprehensive post was sufficient to
solve the OP's problem. I was merely correcting your misinformation.
Why should I post a solution if someone has already done so?
[snip]
Mike
Please don't top-post.
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
sorry, that's my fault for not looking at the times!
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsh2ntttdx13kvk@atlantis... On Fri, 26 Nov 2004 12:03:47 +0000 (UTC), Phillip Parr <no@no.com> wrote:
While you say the this operator was correct, you don't explain why his script didn't work.
Because I assume that Fred's more comprehensive post was sufficient to solve the OP's problem. I was merely correcting your misinformation.
Why should I post a solution if someone has already done so?
[snip]
Mike
Please don't top-post.
-- Michael Winter Replace ".invalid" with ".uk" to reply by e-mail. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dariusz |
last post by:
I have a small form that on button press submits to a PHP file for further
processing into a database. I have to change the script as it allows
blank / nothing to be submitted to the database. ...
|
by: Antoni |
last post by:
Hello
I wondered if this script seemed correct? The user should enter a
userid and password in two text fields, and then pass these values to
the method login_user.
Could I ask, is there any...
|
by: Alistair |
last post by:
hey peoples.
I have a simple form (currently two fields) which is then passed to an ASP
page thats stores the data in a dbase
I have an error checking script which I can't get to work. the...
|
by: Jack |
last post by:
Hi,
I have a form when loaded, retrieves record from an access table. Among
other fields there is a check box called FinalUpdate. This is tied to a field
in Access of type Yes/No.
The form...
|
by: Gawie Marais |
last post by:
hi all,
i have a form and would like to check two fields.
if field 1 containes the letter 'c' and the other field contains
'undefined', then an error should apprear ina box on the screen.
can...
|
by: reinhout |
last post by:
Hi everyone,
I have made a script that checks if content is entered in the html boxes and if the required fields are empty, their border lights red.
This all works, but if I try to make a...
|
by: fperri |
last post by:
Hi,
I have a table with over 20 columns. Seven of these of these columns correspond to a filter on a search form. Based on what is selected on the search form, and what is in these seven fields in...
|
by: maxx429 |
last post by:
I am trying to check if notes have been added to a Memo field on a form if certain other fields have changed. Example: If the user ticks a particular check box on the form, I want to force them to...
|
by: john.cole |
last post by:
I have searched all the groups I can, and I still haven't been able to
come up the solution I need. I have the following problem.
In my form named sbfrmSpoolList, I am entering a job, spool and...
|
by: geetamadhavi |
last post by:
Hi All,
I have developed a php applciaiton where a new window is opening on checking the whether valid user orntot how to make that in same window after checking i have die(' not valid user ' ); i...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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...
|
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...
|
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,...
| |