|  | Fire firefox? |  | |
| | | GarryJones |  |
| Posted: Mon Sep 01, 2008 10:34 am Post subject: Fire firefox? |  |
| |  | |
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....
LINK
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"> <input type="button" value="Not OK" onClick="history.back()"> </td> </tr> </table> </form>
</BODY> </HTML> |
| |
| | | Joost Diepenmaat |  |
| Posted: Mon Sep 01, 2008 10:34 am Post subject: Re: Fire firefox? |  |
GarryJones <morack@algonet.se> writes:
| Quote: | 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; } // ...
-- Joost Diepenmaat | blog: LINK | work: LINK |
| |
| | | GarryJones |  |
| Posted: Mon Sep 01, 2008 12:47 pm Post subject: Re: Fire firefox? |  |
| |  | |
On 1 Sep, 12:41, Joost Diepenmaat <jo...@zeekat.nl> wrote:
| Quote: | GarryJones <mor...@algonet.se> writes: This is driving me simply crazy ... snip Most browsers....... ... 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 |
| |
| | | Dr J R Stockton |  |
| Posted: Tue Sep 02, 2008 11:34 am Post subject: Re: Fire firefox? |  |
| |  | |
In comp.lang.javascript message <87wshw5esa.fsf@zeekat.nl>, Mon, 1 Sep 2008 12:41:41, Joost Diepenmaat <joost@zeekat.nl> posted:
| Quote: | 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.
-- (c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05. Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A. Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News. No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News. |
| |
| | | The Magpie |  |
| Posted: Tue Sep 02, 2008 12:56 pm Post subject: Re: Fire firefox? |  |
GarryJones wrote:
| Quote: | 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" |
| |
| | | optimistx |  |
| Posted: Tue Sep 02, 2008 1:34 pm Post subject: Re: Fire firefox? |  |
| |  | |
The Magpie wrote:
| Quote: | GarryJones wrote: 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 ... |
| |
| | | Dr J R Stockton |  |
| Posted: Wed Sep 03, 2008 10:40 am Post subject: Re: Fire firefox? |  |
| |  | |
In comp.lang.javascript message <g9jk7f$adf$1$8300dec7@news.demon.co.uk> , Tue, 2 Sep 2008 15:56:57, The Magpie <usenet@pigsinspace.co.uk> posted:
| Quote: | GarryJones wrote: 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.
| Quote: | 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>
-- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME. Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links. Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036) Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036) |
| |
|
|