Works in Firefox, not in IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chubbard1
    New Member
    • Mar 2008
    • 3

    Works in Firefox, not in IE

    I have an extremely simple script that works fine in Firefox and Opera, but does not work in IE or Safari. The script looks like this.

    Code:
    <script language="JavaScript" type="text/javascript">
      function autofill(units,uprice) {
        invitems.Units.value=units;
        invitems.UnitPrice.value=uprice;
      }
    </script>
    My form looks like this.

    [HTML]<form name="invitems" >
    <table>
    <tr>
    <td>
    <select name="CategoryI D" size="1">
    <option onClick="autofi ll('','')">&nbs p;</option>
    <option onClick="autofi ll('months','20 .00')">Service1 </option>
    <option onClick="autofi ll('hours','75. 00')">Service 2</option>
    <option onClick="autofi ll('hours','50. 00')">Service 3</option>
    </select>
    </td>
    <td><input type="text" name="Units" size="5" maxlength="10"> </td>
    <td><input type="text" name="UnitPrice " size="5" maxlength="10"> </td>
    </tr>
    </table>
    </form>
    [/HTML]
    Can anyone tell me what I need to do to get this to work in IE/Safari?
  • chubbard1
    New Member
    • Mar 2008
    • 3

    #2
    Works in Firefox, not in IE

    I have an extremely simple script that works fine in Firefox and Opera, but does not work in IE or Safari. The script looks like this.

    Code:
    <script language="JavaScript" type="text/javascript">
      function autofill(units,uprice) {
        invitems.Units.value=units;
        invitems.UnitPrice.value=uprice;
      }
    </script>
    My form looks like this.

    [HTML]<form name="invitems" >
    <table>
    <tr>
    <td>
    <select name="CategoryI D" size="1">
    <option onClick="autofi ll('','')">&nbs p;</option>
    <option onClick="autofi ll('months','20 .00')">Service1 </option>
    <option onClick="autofi ll('hours','75. 00')">Service 2</option>
    <option onClick="autofi ll('hours','50. 00')">Service 3</option>
    </select>
    </td>
    <td><input type="text" name="Units" size="5" maxlength="10"> </td>
    <td><input type="text" name="UnitPrice " size="5" maxlength="10"> </td>
    </tr>
    </table>
    </form>[/HTML]

    Can anyone tell me what I need to do to get this to work in IE/Safari?

    Comment

    • mrhoo
      Contributor
      • Jun 2006
      • 428

      #3
      I'm not sure about Safari, but IE doesn't let you treat options as elements at all.
      It's almost like they are properties of the select.

      You'll need to write an onchange handler for the select element, and branch your code according to its selectedIndex

      Comment

      • chubbard1
        New Member
        • Mar 2008
        • 3

        #4
        Well that pretty much bites the big one. The code I submitted was simple to show only the part that was broken, but for the actual implementation, it is pretty important that each <option> have its own data associated with it because those <option> tags are dynamically generated from a database query. I suppose I could have the javascript function dynamically written instead of the <option> tags, but that makes for more work, more possible complications, and double the queries to the database. *sigh* This is not the first time I've seen IE force me to be inefficient, and I suppose it won't be the last time either.

        Comment

        • mrhoo
          Contributor
          • Jun 2006
          • 428

          #5
          Yeah, well let me know when people start paying for sites that don't work in IE and Safari. It would be swell if everyone used firefox, but they don't and they won't...

          Comment

          Working...