By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
461,969 Members | 599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 461,969 IT Pros & Developers. It's quick & easy.

javascript working incorrectly in mozilla with select element

P: 2
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/GlobalParameters" onkeypress="return webDefaultFormKeyHandler(this,event,IDN_Conversion _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="JavaScript1.2" type="text/javascript">
var187_0Object = new SelectBox("var187_0","varValue1");
var187_0Object.add("enable","enable");
var187_0Object.add("disable","disable");
var187_0Object.setValue("disable");
</script></td></tr>[/HTML]

SelectBox is defined in another javascript file, and the code goes like this:
Expand|Select|Wrap|Line Numbers
  1. function SelectBoxSetValue(value) {
  2.   options = this.sel.options;
  3.   for (i=0;i<options.length;i++) {
  4.     if (options[i].value == value) {
  5.       this.sel.selectedIndex = i;
  6.     }
  7.   }
  8. }
  9.  
  10. function SelectBoxAdd(text,value)
  11. {
  12.   ops = this.sel.options;
  13.   for (i=0;i<ops.length;i++) {
  14.     if (ops[i].text == text) {
  15.       return;
  16.     }
  17.   }  
  18.   o = document.createElement("OPTION");
  19.   o.text = text;
  20.   o.value = value;
  21.   addoption(this.sel,o);  
  22. }
  23.  
  24. function SelectBox(name,parentId) {
  25.   this.sel  = document.createElement("SELECT");
  26.   this.sel.name = name;
  27.   this.sel.id   = name;
  28.   if (parentId != null) {
  29.     this.par   = document.getElementById(parentId);   
  30.   } else {
  31.     this.par   = document;
  32.   }
  33.   this.add      = SelectBoxAdd;
  34.   this.remove   = SelectBoxRemove;
  35.   this.setValue = SelectBoxSetValue;
  36.   this.par.appendChild(this.sel);
  37. }
  38.  
Can anyone give some pointers as to why this wouldn't work in Firefox?
Thanks in advance
Sep 6 '07 #1
Share this Question
Share on Google+
3 Replies

acoder
Expert Mod 15k+
P: 16,027
Welcome to TSDN!

Perhaps line 31 should be
Expand|Select|Wrap|Line Numbers
  1. this.par = document.body;
Sep 7 '07 #2

P: 2
Welcome to TSDN!

Perhaps line 31 should be
Expand|Select|Wrap|Line Numbers
  1. this.par = document.body;
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 :))
Sep 9 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Glad you got it working and thanks for posting your solution.

Post again should you need help on a JS problem.
Sep 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.