Fire firefox?

G

GarryJones

This is driving me simply crazy ... this simple (?) code works in Msie
but not Firefox.

function checkform ()
{
if (document.regfrms.cgbx.itm1.checked == false &&
document.regfrms.cgbx.itm2.checked == false){
alert( "You have to choose one" );
document.regfrms.cgbx.itm1.focus();
return false ;
}
return true ;
}


It checks the values of 2 radio buttons and if neither have been
pressed it alerts the user.

See this for yourselves....

http://www.morack.se/firedfox.html

So the question (before I request the British Government to make FOX
hunting compulsory) is how does firefox handle the checked status of
radio buttons..... ?

Any help and YOU are a genius...
Garry Jones
Sweden
PS, offendinfg code, enitre file...

<HTML>
<HEAD><TITLE>Test</TITLE>
</HEAD>
<BODY style="BACKGROUND: none transparent scroll repeat 0% 0%; MARGIN:
0px">
<script language="JavaScript" type="text/javascript">
function checkform ()
{
if (document.regfrms.cgbx.itm1.checked == false &&
document.regfrms.cgbx.itm2.checked == false){
alert( "You have to choose one" );
document.regfrms.cgbx.itm1.focus();
return false ;
}
return true ;
}

</script>
<FORM action="dosomething.php" method="post" name="regfrms"
onSubmit="return checkform()">
<TABLE width="600" border="1" cellspacing="0" cellpadding="2">
<tr>
<td >
<input title="This is item 1" type="radio" id="itm1" value="yes"
name="cgbx" >
Item 1
<br>
<input title="This is item 2" type="radio" id="itm2" value="yes"
name="cgbx" >
Item 2
<br>
</td></tr>
<td width="600" >
<input type="Submit" value = "Ok">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="Not OK" onClick="history.back()">
</td>
</tr>
</table>
</form>

</BODY>
</HTML>
 
J

Joost Diepenmaat

GarryJones said:
This is driving me simply crazy ... this simple (?) code works in Msie
but not Firefox.

function checkform ()
{
if (document.regfrms.cgbx.itm1.checked == false &&
document.regfrms.cgbx.itm2.checked == false){
alert( "You have to choose one" );
document.regfrms.cgbx.itm1.focus();
return false ;
}
return true ;
}

Most browsers do not provide access to elements by id or forms by name
via the document.MyIdOrName short-cut. And as far as I know, your
cgbx.itm2 (where itm2 is an ID, and cgbx is the name of the radio(s))
isn't portable either (I may be wrong about *that* because this is the
first time I've ever seen the construct).

Since you're using IDs /anyway/, why not do:

if (!(document.getElementById("itm1").checked ||
document.getElementById("itm2").checked)) {
alert("You have to choose one");
return false;
}
// ...
 
G

GarryJones

... snip
, why not do:

Thanks. It works (of course).

"Most browsers" is the problem here.

The current stats (source Wiki) are
Msie: 78.30%
Netscape Navigator: 0.06%
Netscape/Mozilla/Firefox: 16.36%
Opera: 0.81%
Safari: 3.41%

As a homebrewer with nothing other to go I googled for an answer to my
problem and found the (msie biased) code I then used.

What I can never appreciate enough is guys like yourself who bother to
read questions from innocent newbies like myself and spend time
replying to us. You have solved a major headache for me as I found
nothing on the net to solve my problem. Giving the onset of permanant
connections to the Internet I am just so pleased that the USEnet
community still exists and continues to outweigh the online web forums
in quality and efficiency. As good to day as it was when I first
posted to the IBM Knowledge base back in the summer of 1979. (yes,
thats right, 30 years next year.....)

Thanks again, if you're ever in Sweden the beers are on me...

Garry Jones
The(?) Englishman in Sweden
 
D

Dr J R Stockton

Mon said:
Since you're using IDs /anyway/, why not do:

if (!(document.getElementById("itm1").checked ||
document.getElementById("itm2").checked)) {
alert("You have to choose one");
return false;
}

I'd prefer, largely because of the comment-value of "OK",

OK = document.getElementById("itm1").checked ||
document.getElementById("itm2").checked
if (!OK) alert("You have to choose at least one")
return OK

<FAQENTRY> On the need to test in both IE & non-IE, and briefly why.

To OP : If something, even something simple, does not work, simplify
further.

For example, in my js-quick.htm there is a div with ID=Divn. If I type
the word Divn into the textarea and execute it, then :
IE: Result line [object];
FF: Result line blank,
Error console "Error: Divn is not defined".

So to simplify try alert(document.regfrms.cgbx.itm1.checked) and
consider the result.
 
T

The Magpie

GarryJones said:
This is driving me simply crazy ... this simple (?) code works in Msie
but not Firefox.

[snip "document.forms" query]

How often do we get versions of this query about MSIE using the
"name-shortcut" addressing and other browsers not doing?

I presume it is already in the FAQ, so perhaps it would help if we
regularly post a message in the group to the effect of "Here is where
you find the FAQ - read it before you ask a question we keep getting
asked"
 
O

optimistx

The said:
GarryJones said:
This is driving me simply crazy ... this simple (?) code works in
Msie but not Firefox.

[snip "document.forms" query]

How often do we get versions of this query about MSIE using the
"name-shortcut" addressing and other browsers not doing?

I presume it is already in the FAQ, so perhaps it would help if we
regularly post a message in the group to the effect of "Here is where
you find the FAQ - read it before you ask a question we keep getting
asked"

It is really annoying to see the same type of problem all the time. Those
people, who hava opportunity use javascript even 24/7/365 in their work and
hobbies might have difficulty to imagine the position a person, who only
occasionally use javascript. These random turists might use 3-4 other
languages fluently, but are astonishingly newbielike in javascript. FAQ is
about 70 kilobytes, and its takes at least an hour to read it thoroughly,
but
even after that it is not necessarily easy to find out that a 'name
shortcut' is
the problem.
If there are too easy questions for the experts, what about leaving them
to less-experts to answer? Thus they get experience to learn posting
javascript.
If there is a rule that every time before posting I MUST use at least
one hour to google and read various references, then ...
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
GarryJones said:
This is driving me simply crazy ... this simple (?) code works in Msie
but not Firefox.

[snip "document.forms" query]

How often do we get versions of this query about MSIE using the
"name-shortcut" addressing and other browsers not doing?

I presume it is already in the FAQ,

One should read the FAQ before making comments on the FAQ or posting
questions or answers which the FAQ might treat (FAQ 2.3).

FAQ 4.41 provides the OP's answer. However, I have some doubts about
its "The best approach". A document is a two-dimensional tree (being
2-D, the children of each parent are ordered), and uniquely labelling
each leaf and node that needs to be referred to does not make use of
possibilities indicated by doc.frm1.IN & doc.frm2.IN. For example, my
holidays.htm has five buttons (for 5 locations) each of which generates
a complex table; the tables are data-driven for size and content, and
their variable elements are much better addressed structurally rather
than globally. Structural addressing deserves mention.
so perhaps it would help if we
regularly post a message in the group to the effect of "Here is where
you find the FAQ - read it before you ask a question we keep getting
asked"

The daily "FAQ Topic" posts are supposed also to serve that purpose; see
FAQ sec 1 para 4.

<FAQENTRY> At an early use of "FAQ" within the FAQ, the full "Frequently
Asked/Answered Questions" should be given. </FAQENTRY>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top