www.webdeveloper.com
Results 1 to 14 of 14

Thread: Why wont this work in IE or FF

  1. #1
    Join Date
    Oct 2009
    Location
    Manitoba
    Posts
    36

    Why wont this work in IE or FF

    Will work in safari, and Google Chrome, but wont work in IE and FF

    To big of code:

    http://www.jamesplamondon.netne.net/pizzahut.html

  2. #2
    Join Date
    Aug 2009
    Posts
    593
    FireFox is telling me that is cannot find the element named "pizza1t1".

    The problem is how you are referencing the elements:

    Eg

    Code:
    document.getElementById("pizza1t1").selectedIndex; //Recommended
    //OR
    document.form1.pizza1t1.selectedIndex;
    Also remember that every statement must be terminated with a semi-colon ; Otherwise you will get syntax errors.

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by thraddash View Post

    Code:
    document.getElementById("pizza1t1").selectedIndex; //Recommended
    //OR
    document.form1.pizza1t1.selectedIndex;
    Not really. The lines above are not equivalent. First is a reference by id, the second is a reference by name. id and name are different things.
    Quote Originally Posted by thraddash View Post
    Also remember that every statement must be terminated with a semi-colon ; Otherwise you will get syntax errors.
    No. The semicolon is not required in javascript, unless the next statement is written in the same line. Anyway, I agree it is a good habit to terminate the statements with a semicolon.

  4. #4
    Join Date
    Aug 2009
    Posts
    593
    Was there a point to that post?

    The element referencing examples were there as a choice, as there are referencing errors in the website provided. Pick one.

    You are looking for problems if you don't write Javascript the way it was intended.

  5. #5
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    The jamesplamondon's code has too many errors. basically, they are related to the wrong reference. From this point of view thraddash is right. I was only to point out the difference between id and name. IE is able to take a name as id and to refer an element directly by its id/name, which is not javascript standard.

    For instance:
    Code:
    sel=pizza1t1.selectedIndex;
    Should rather be:
    Code:
    sel=document.form1.pizza1t1.selectedIndex;
    //or
    sel=document.forms['form1'].elements['pizza1t1'].selectedIndex;
    //or even
    sel=document['form1']['pizza1t1'].selectedIndex;
    because all the elements of the document should be refered starting from the document object, not directly.

    Note: The examples above request the name attribute.

  6. #6
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    As Kor has most justifiably noted.... the scripting does not comply with standards.
    The page does not comply with standards.
    NEITHER jamesplamondon OR thraddash bothered to try to validate the markup where errors are obvious... I know there are stickies around the forum saying not to ask what's wrong until you have validated the code. hmmm....

    oh well.

  7. #7
    Join Date
    Oct 2009
    Location
    Manitoba
    Posts
    36
    Okay, i will be give that a try today

    P.S im only a noob in javascript only been working on simple javascript for 2 weeks.

  8. #8
    Join Date
    Aug 2009
    Posts
    593

    Cool A Gift

    I have corrected the javascript and html errors, and attached the file.
    This has been tested in Firefox and IE6.

    opifex: you could consider actually helping instead of just running your mouth off.
    Attached Files Attached Files

  9. #9
    Join Date
    Oct 2009
    Location
    Manitoba
    Posts
    36
    Thanks alot Thraddash! that really helps!

  10. #10
    Join Date
    Aug 2009
    Posts
    593
    Your welcome.

  11. #11
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    thraddash - opifex was helping. He was pointing out that validating the code is a good first step to debugging.

    Of course I think that is a little too much to ask for newbie - but he does have a point and there is no need to be rude.

    jamesplamondon - Notice that one of the things thraddash did was to add both name and id attributes to each element of your form. That is because it is easier in JavaScript to check things by using their ID, but when a form gets submitted to a server it's the NAME that is used. It's a good habit to get into to just always use both and make sure they are set to the same value.

  12. #12
    Join Date
    Aug 2009
    Posts
    593
    Just to put things straight, validating the code is NOT my responsibility, but it obviously helps in clearng errors. Besides the problems were very minor and could have been overlooked. I take great offense at unconstructive critasism.

    BTW I did not add any id's or names's to the code, they were already there. You are not giving jamesplamondon enough credit.
    Last edited by thraddash; 10-07-2009 at 05:15 PM.

  13. #13
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    Quote Originally Posted by thraddash View Post
    Just to put things straight, validating the code is NOT my responsibility...
    Don't want to offend, but valid code is everybody's responsibility. All browsers ARE NOT created equal and some are just more picky than others when it comes to errors.

    Now that the basic premise of this form is working it might be a good idea to change the allow variables
    HTML Code:
    var r = {
    					'special':/[\W]/g,
    					'notnumbers':/[^\d]/g
    				};
    to
    HTML Code:
    'special':/[^\W|\s]/g,
    so that you can put in spaces.

  14. #14
    Join Date
    Aug 2009
    Posts
    593
    My friend, you have me all wrong. I subject myself to validation constantly, but I don't encourage shrugging off a person asking for help because they don't conform to standards, if they did then there is no longer a purpose for us.

    If you were offended by my previous post, I appologise. Hopefully I can sleep better at least saying that.

    Validation tools I used for reference were:

    http://validator.w3.org/
    http://www.jslint.com/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles