473,399 Members | 4,177 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,399 software developers and data experts.

JavaScript Issue

Hi,
I wrote this function to check the validity of the text field,
StudentID if a radio button associated with it is clicked. The function
does not work...
function checkValidity(this) {

// Check the Radio buttons for which is checked.

var sid;
// it is group radio button and I am checking for the first one which
is associated with the text box of StudentID

for (var i=0;i <document.form1.searchby.length; i++)
{
if (document.form1.searchby[0].checked = true)
{

sid = document.form1.StudentID.value;

if (sid.length == 0)
{
alert("Student ID is Missing ");
return false;
}
}
}
}

Jun 19 '06 #1
9 1295
kr******@gmail.com said the following on 6/19/2006 1:38 PM:
Hi,
I wrote this function to check the validity of the text field,
StudentID if a radio button associated with it is clicked.
Use a checkbox. It will make your life simpler and if it's only purpose
is to tell whether a field should be used or not then a checkbox is more
appropriate.

The function does not work...
function checkValidity(this) {
Your parameter name is about the worst name you could choose. You don't
use it in your function but if you did then your function still wouldn't
work and wouldn't do what you think it would do.
// Check the Radio buttons for which is checked.
var sid;
// it is group radio button and I am checking for the first one which
is associated with the text box of StudentID

for (var i=0;i <document.form1.searchby.length; i++)
{
if (document.form1.searchby[0].checked = true)


<URL: http://www.jibbering.com/faq/faq_notes/form_access.html#faBut>

Explains how to get a reference to a Radio Button.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 19 '06 #2
JRS: In article <11**********************@f6g2000cwb.googlegroups. com>,
dated Mon, 19 Jun 2006 10:38:24 remote, seen in
news:comp.lang.javascript, kr******@gmail.com posted :
for (var i=0;i <document.form1.searchby.length; i++)
{
if (document.form1.searchby[0].checked = true)
That will assign true to document.form1.searchby[0].checked and the
following code will always be executed. You might have meant
searchby[i] too.
{

sid = document.form1.StudentID.value;

if (sid.length == 0)
{
alert("Student ID is Missing ");
return false;
}
}
}
}


AFAICS it is never necessary to use ==true or ==false, and doing so
indicates a fundamental lack of understanding.

Code in News articles, etc., should always by copy'n'pasted rather than
retyped.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of 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.
Jun 20 '06 #3
In article <FJ**************@merlyn.demon.co.uk>, Dr John Stockton
<jr*@merlyn.demon.co.uk> writes

<snip>
AFAICS it is never necessary to use ==true or ==false, and doing so
indicates a fundamental lack of understanding.

<snip>

It doesn't indicate a fundamental lack - it runs the risk of falling
foul of javascript's complicated rules for ==. For instance,

var x = 3;
if (x)
alert("True");
else
alert("False");

says 'true', whereas

var x = 3;
if (x == true)
alert("True");
else
alert("False");

says 'false'.

John
--
John Harris
Jun 21 '06 #4
JRS: In article <3E**************@jgharris.demon.co.uk>, dated Wed, 21
Jun 2006 21:10:07 remote, seen in news:comp.lang.javascript, John G
Harris <jo**@nospam.demon.co.uk> posted :
In article <FJ**************@merlyn.demon.co.uk>, Dr John Stockton
<jr*@merlyn.demon.co.uk> writes

<snip>
AFAICS it is never necessary to use ==true or ==false, and doing so
indicates a fundamental lack of understanding.

<snip>

It doesn't indicate a fundamental lack - it runs the risk of falling
foul of javascript's complicated rules for ==. For instance,

It DOES indicate a fundamental lack - AND it runs the risk of falling
foul of javascript's complicated rules for ==.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of 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.
Jun 22 '06 #5
Dr John Stockton said the following on 6/22/2006 6:55 AM:
JRS: In article <3E**************@jgharris.demon.co.uk>, dated Wed, 21
Jun 2006 21:10:07 remote, seen in news:comp.lang.javascript, John G
Harris <jo**@nospam.demon.co.uk> posted :
In article <FJ**************@merlyn.demon.co.uk>, Dr John Stockton
<jr*@merlyn.demon.co.uk> writes

<snip>
AFAICS it is never necessary to use ==true or ==false, and doing so
indicates a fundamental lack of understanding.

<snip>

It doesn't indicate a fundamental lack - it runs the risk of falling
foul of javascript's complicated rules for ==. For instance,

It DOES indicate a fundamental lack - AND it runs the risk of falling
foul of javascript's complicated rules for ==.


Adding ==true and ==false, to me, falls into the same category of
semicolons but the opposite. If you are not sure, use the ==true and
==false just to be sure. It's a "safer" approach, if there is one.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 22 '06 #6
Randy Webb <Hi************@aol.com> writes:
Adding ==true and ==false, to me, falls into the same category of
semicolons but the opposite. If you are not sure, use the ==true and
==false just to be sure. It's a "safer" approach, if there is one.


The problem is that it is not safer.

Try this:
---
var r = [];
for (var i = 0; i < 5; i++) {
if (i) { r.push(","); }
r.push(i);
}
alert(r.join("")); // yes I know there are simpler ways :)
---
Whoever wrote this knows the rules for converting numbers to booleans.
The result is alerting the string "0,1,2,3,4".

Now add someone who is less sure about it, and just to be "safer" he
adds "==true" to get "if (i == true) { ...".

The result now becomes "0,1234".
If you don't know for certain that the value in the condition is a
boolean, adding " == true" or " == false" is downright dangerous.

If you do know it, it's just not necessary.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 22 '06 #7
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote:
The problem is that it is not safer.

Try this: <--->
var r = [];
for (var i = 0; i < 5; i++) {
if (i) { r.push(","); }
r.push(i);
}
alert(r.join("")); // yes I know there are simpler ways :)
</---> Whoever wrote this knows the rules for converting numbers to
booleans. The result is alerting the string "0,1,2,3,4".

Now add someone who is less sure about it, and just to be
"safer" he adds "==true" to get "if (i == true) { ...".

The result now becomes "0,1234".

If you don't know for certain that the value in the condition is
a boolean, adding " == true" or " == false" is downright
dangerous.

If you do know it, it's just not necessary.


That can also be written as:

var r = [];
for (var i = 0; i < 5; i++) {
if (i != 0) { r.push(","); }
r.push(i);
}
alert(r.join("")); // yes I know there are simpler ways :)

which works upon the same principles as using ==. Right? After
all:

if (i)

literally translates to:

if (i != 0)

and not to:

if (i == 0)

If the suggestion involves deploying == when appropriate, that
leans towards the fact the end-user knows that when to deploy
== versus when to utilize !=, as in your example. ;-)

Nice try. Nice example. Thanks for passing it along.

--
Jim Carlock
Post replies to the group.
Jun 23 '06 #8
JRS: In article <mu******************************@comcast.com>, dated
Thu, 22 Jun 2006 15:34:21 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
Dr John Stockton said the following on 6/22/2006 6:55 AM:
JRS: In article <3E**************@jgharris.demon.co.uk>, dated Wed, 21
Jun 2006 21:10:07 remote, seen in news:comp.lang.javascript, John G
Harris <jo**@nospam.demon.co.uk> posted :
In article <FJ**************@merlyn.demon.co.uk>, Dr John Stockton
<jr*@merlyn.demon.co.uk> writes

<snip>
AFAICS it is never necessary to use ==true or ==false, and doing so
indicates a fundamental lack of understanding.
<snip>

It doesn't indicate a fundamental lack - it runs the risk of falling
foul of javascript's complicated rules for ==. For instance,

It DOES indicate a fundamental lack - AND it runs the risk of falling
foul of javascript's complicated rules for ==.


Adding ==true and ==false, to me, falls into the same category of
semicolons but the opposite. If you are not sure, use the ==true and
==false just to be sure. It's a "safer" approach, if there is one.


Being unsure on the use of Boolean values clearly indicates a
fundamental lack of understanding - though alas not an uncommon one.

##

http://www.zdnetasia.com/techguide/w...9369022,00.htm
was evidently written by someone whose local time matched yours ...

Since it was advertised yesterday beside the display of this group in
Google, we may see ...

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of 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.
Jun 23 '06 #9
In article <Wl**************@merlyn.demon.co.uk>, Dr John Stockton
<jr*@merlyn.demon.co.uk> writes

Thinking that this

<snip>
> AFAICS it is never necessary to use ==true or ==false, and doing so
> indicates a fundamental lack of understanding.
<snip>

is a consequence of this

<snip>Being unsure on the use of Boolean values clearly indicates a
fundamental lack of understanding - though
shows a fundamental lack of understanding of logic that is
alas not an uncommon one.

<snip>

John
--
John Harris
Jun 25 '06 #10

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

Similar topics

1
by: Nathan DeBardeleben | last post by:
This may seem wierd, and I know someone asked this question before but was told they were doing it the hard way. Unlike them, I do not have shell access to the machine where this javascript runs....
6
by: TJ | last post by:
Hello All, I posted a question a few days ago entitled "Select element with no selected options". Over the course of the discussion, RobG wrote: > This is just an example, it is not really...
3
by: Jason | last post by:
I have two applications that I wrote that use asp and javascript source files. Recently both of these applications starting acting strange on my test box. Image icons will randomly stop showing...
3
by: fbwhite | last post by:
I am having an issue (maybe two issues) in my application regarding a stylesheet not loading and I am getting Javascript Errors. If I clean out a client's temporary internet files and then browse...
4
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a...
16
by: Eric | last post by:
I have a user of a web application written in Java/JSP that is unable to login to the site simply because certain links on the page do not run when they are clicked. Other popups using Javascript...
6
by: kenundrum | last post by:
Hey all, I am having an issue with XML/XSLT and JavaScript in my ASP.NET page that I am creating. I first want to apologize if i placed this in the wrong category. Since there were three different...
33
by: Simon Brooke | last post by:
I'm working on a system which uses Google maps. I want the user to see a map of more or less where (s)he is in the world when (s)he first comes to the system. So the obvious thing seemed to be to...
3
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, This is an issue that happens to me and everybody else I know and I've never found a way around it. In Visual Studio (currently using 2003 but the same has happened for me in 2005 and...
1
by: a.bavdhankar | last post by:
Hi, Newbie Question: Applicable to dotnet 2.0 I am getting javasacript error message as Expected ')' but all script works fine on other machine. There is no syntax error in the script but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.