javascript working incorrectly in mozilla with select element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yurcheg
    New Member
    • Sep 2007
    • 2

    #1

    javascript working incorrectly in mozilla with select element

    Hi, I've searched the forum for this problem but haven't found anything relevant.
    I've got a javascript code which dynamically creates list-boxes in a form. It
    works perfectly fine in IE, but in Firefox 2 I change the selected value in
    a list-box but nothing gets submitted via POST.
    The dynamic list-box creation code looks like this:
    [HTML]
    <form name="form0" method=POST action="/dynamic/AppDirector/Global/GlobalParameter s" onkeypress="ret urn webDefaultFormK eyHandler(this, event,IDN_Conve rsion_Page_Set_ Handler)">
    <table border=0>
    <tr><td class="varName" >
    <b>Open New Entry When Source Port Different</b>
    </td>
    <td class="varValue " id="varValue1" >
    <input type="hidden" name="mibId_0" value="187">
    <script language="JavaS cript1.2" type="text/javascript">
    var187_0Object = new SelectBox("var1 87_0","varValue 1");
    var187_0Object. add("enable","e nable");
    var187_0Object. add("disable"," disable");
    var187_0Object. setValue("disab le");
    </script></td></tr>[/HTML]

    SelectBox is defined in another javascript file, and the code goes like this:
    [CODE=javascript]
    function SelectBoxSetVal ue(value) {
    options = this.sel.option s;
    for (i=0;i<options. length;i++) {
    if (options[i].value == value) {
    this.sel.select edIndex = i;
    }
    }
    }

    function SelectBoxAdd(te xt,value)
    {
    ops = this.sel.option s;
    for (i=0;i<ops.leng th;i++) {
    if (ops[i].text == text) {
    return;
    }
    }
    o = document.create Element("OPTION ");
    o.text = text;
    o.value = value;
    addoption(this. sel,o);
    }

    function SelectBox(name, parentId) {
    this.sel = document.create Element("SELECT ");
    this.sel.name = name;
    this.sel.id = name;
    if (parentId != null) {
    this.par = document.getEle mentById(parent Id);
    } else {
    this.par = document;
    }
    this.add = SelectBoxAdd;
    this.remove = SelectBoxRemove ;
    this.setValue = SelectBoxSetVal ue;
    this.par.append Child(this.sel) ;
    }
    [/CODE]

    Can anyone give some pointers as to why this wouldn't work in Firefox?
    Thanks in advance
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    Perhaps line 31 should be [CODE=javascript]this.par = document.body;[/CODE]

    Comment

    • yurcheg
      New Member
      • Sep 2007
      • 2

      #3
      Originally posted by acoder
      Welcome to TSDN!

      Perhaps line 31 should be [CODE=javascript]this.par = document.body;[/CODE]
      Thanks!
      I managed to solve the problem, fortunately. I had the<form> element as a direct son of <table>, and firefox didn't like it that much :))

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Glad you got it working and thanks for posting your solution.

        Post again should you need help on a JS problem.

        Comment

        Working...