SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    Albany, NY
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Javascript runs fine in IE, not Firefox.

    I created a web form that is a table view with 15 rows and 5 colums. the bottom row and right most column are for calculated values. When a user enters a value in any of the fields, calculated values are adjusted. I have the form working perfectly in IE, but in Forefox, the calculated value fields remain blank. To keep users from modifying the totals, I set the calculated fields, disadled="disabled". Since disabled fields don't pass when form is submitted via post, I created a hidden field to hold the value. The hidden field has the same name as the disabled field except the last letter of the name duplicates. I.E. PreKDiscrepancy & PreKDiscrepancyy.

    Here is an example of the calculation for the first row:

    Code:
     
    DH = parseInt(document.forms(0).PreKCurrentTrained.value, 10) + parseInt(document.forms(0).PreKAbsent.value, 10);
    DH = DH + parseInt(document.forms(0).PreKOptOut.value, 10);
    DH = parseInt(document.forms(0).PreKEnroll.value, 10) - DH;
                  
    document.forms(0).PreKDiscrepancy.value = DH
    document.forms(0).PreKDiscrepancyy.value = DH
    what about the code does firefox not like?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Why are you using "disabled" and then having to create a hidden field to pass the value when "readonly" disallows entry into the field but still passes it so as to do away with your hidden field.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Why are you using "disabled" and then having to create a hidden field to pass the value when "readonly" disallows entry into the field but still passes it so as to do away with your hidden field.


    Also, you didn't say what results you get in Google Chrome, Safari or Opera. Do they produce the same result as IE or the same as Firefox?
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    Albany, NY
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. I figured out what to do to get the JS to work, but I don't know why the original code didn't work

    Answer:
    use
    Code:
     DH = parseInt(document.getElementById('PreKCurrentTrained').value, 10) + parseInt(document.getElementById('PreKAbsent').value, 10);
    rather than
    Code:
    DH = parseInt(document.forms(0).PreKCurrentTrained.value, 10) + parseInt(document.forms(0).PreKAbsent.value, 10);
    For some reason document.forms(0).element... is not supported by all browsers where as getElementById is.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Why are you using "disabled" and then having to create a hidden field to pass the value when "readonly" disallows entry into the field but still passes it so as to do away with your hidden field.


    Also, you didn't say what results you get in Google Chrome, Safari or Opera. Do they produce the same result as IE or the same as Firefox?


    Also you shouldn't be using parseInt unless you are converting between number bases. To convert a string to a number use either num = Number(str) or num = (+str);
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    Albany, NY
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was using disabled fields because I want to have the fields gray'd out. Readonly looks like a regular field that is broken and not typable.

    As for the other browsers your guess is as good as mine. I do not have them installed. I originally wasn't going to bother testing in another browser since the code runs on a sharepoint site. Sharepoint sites, by default do not support browsers other that IE since the site is coded to use active x. I ran into the problem answering a question for a user who was trying to use firefox. Someday Microsoft might change the software to work in other browsers. Better to write cross browser compliant code and have it work than to have people complain and have to rework the code at a later date when I don't remember how it works.

    Unless parseInt uses a lot more processing power and slows down a page significantly, I'm not rewriting several hundred lines of cod.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by RCDAwebmaster View Post
    IReadonly looks like a regular field that is broken and not typable.
    Only if you don't style it. You can use CSS to style it to look whatever way you like, just as you can style disabled fields so they don't appear to be greyed out Youy should use CSS to define the appearance, not use the wrong HTML just because it defaults to the appearance you want..
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    Albany, NY
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't realize that text boxes could be styled to look greyed out, when in fact they are read only. It's great to learn something new. I'll have to wait for my next app to try this. No sense redesigning a form, pocessing page and the SQL server storred procedure that works.


Tags for this Thread

Bookmarks

Posting Permissions

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