473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Combo box works in IE but appears blank in FF

In IE the combobox apears with data, but in FF the combobox apears blank. Why?



Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript"> 
  2.  
  3. function addOpt(oCntrl, iPos, sTxt, sVal){
  4.  
  5. var selOpcion=new Option(sTxt, sVal);
  6. eval(oCntrl.options[iPos]=selOpcion);
  7. }
  8.  
  9. function cambia(oCntrl,valor){
  10.  
  11. while (oCntrl.length) oCntrl.remove(0);
  12. {
  13.  
  14. var selObj = document.getElementById('ta');
  15. var selIndex = selObj.selectedIndex;
  16. var esta = selObj.options[selIndex].text
  17. var txtTextObj = document.getElementById('txtText');
  18. txtTextObj.value = selObj.options[selIndex].text;
  19.  
  20. if (valor ==0)
  21. {
  22. addOpt(oCntrl, 0, "AGOTADO.............................", "0"); 
  23. }
  24. else if (valor >=5)
  25. {
  26. addOpt(oCntrl, 0, "Seleccione la Cantidad..........", "0"); 
  27. addOpt(oCntrl, 1, "1", "1");
  28. addOpt(oCntrl, 2, "2", "2"); 
  29. addOpt(oCntrl, 3, "3", "3");
  30. addOpt(oCntrl, 4, "4", "4"); 
  31. addOpt(oCntrl, 5, "5", "5"); 
  32. }
  33. else
  34. {
  35. addOpt(oCntrl, 0, "Seleccione la Cantidad..........", "0");
  36. var i=1;
  37. while (valor !=0) {
  38.  
  39. addOpt(oCntrl, i, i, i); 
  40. i = i + 1;
  41. valor = valor - 1;
  42. }
  43.  
  44. }
  45.  
  46. }
  47. </script>
  48.  
May 29 '07 #1
33 2288
pbmods
5,821 Expert 4TB
Heya, TomasART. Welcome to TSDN!

Expand|Select|Wrap|Line Numbers
  1.      eval(oCntrl.options[iPos]=selOpcion);
  2.  
Why do you eval this statement?
May 29 '07 #2
Thanks.

This function add the combo data.
May 30 '07 #3
PLease anyone can help me to change this line of code:

eval(oCntrl.options[iPos]=selOpcion);
May 30 '07 #4
This don't work in FF. How i can make it compatible?

eval(oCntrl.options[iPos]=selOpcion);
May 31 '07 #5
acoder
16,027 Expert Mod 8TB
Threads merged - please keep the same problem in one thread.

PS. changed title too.
May 31 '07 #6
acoder
16,027 Expert Mod 8TB
See how you can add and remove options in this tutorial.
May 31 '07 #7
pbmods
5,821 Expert 4TB
Thanks.

This function add the combo data.
Yes, but why is it being eval'ed? Won't it work just as well if you remove the eval statement?
May 31 '07 #8
No it don't work if i remove the eval statement.
Jun 1 '07 #9
acoder
16,027 Expert Mod 8TB
Show an example of the 'cambia' function being called.
Jun 1 '07 #10
ronnil
134 Expert 100+
why not make use of DOM? This function is a bit more complex, but should work in all the major browsers.

Expand|Select|Wrap|Line Numbers
  1. function addOption(ctr,val,txt,index)
  2. {
  3.     var newOpt = document.createElement('option');
  4.     newOpt.value = val;
  5.     newOpt.text = txt;
  6.  
  7.     if(index == undefined)
  8.         index = null;
  9. /**
  10. IE doesn't seem to be able to cope with the last parameter so i put a catch statement in and call it only with the newOpt argument
  11. */
  12.     try{
  13.         ctr.add(newOpt,index);
  14.     } catch(e) {
  15.         try{
  16.             ctr.add(newOpt);
  17.             } catch(e) {
  18.                 alert('You have a sucky browser, please visit http://www.mozilla.org to get a proper one');
  19.             }
  20.     }
  21. }
Jun 1 '07 #11
why not make use of DOM? This function is a bit more complex, but should work in all the major browsers.

Expand|Select|Wrap|Line Numbers
  1. function addOption(ctr,val,txt,index)
  2. {
  3.     var newOpt = document.createElement('option');
  4.     newOpt.value = val;
  5.     newOpt.text = txt;
  6.  
  7.     if(index == undefined)
  8.         index = null;
  9. /**
  10. IE doesn't seem to be able to cope with the last parameter so i put a catch statement in and call it only with the newOpt argument
  11. */
  12.     try{
  13.         ctr.add(newOpt,index);
  14.     } catch(e) {
  15.         try{
  16.             ctr.add(newOpt);
  17.             } catch(e) {
  18.                 alert('You have a sucky browser, please visit http://www.mozilla.org to get a proper one');
  19.             }
  20.     }
  21. }
Thanks, but this do the same like my function. In FF dont'work. See above i will post my code another time with the call function.
Jun 2 '07 #12
ronnil
134 Expert 100+
Odd. I use similar code to produce same result.

Does FF produce any errors? (Tools > Error Console)
Jun 2 '07 #13
Result:

Internet Explorer:



FireFox:



CODE of the first COMBO (how i call the function).

$combo = "<select name=\"ta\" class=\"imputbportada\" onChange=\"cambia(document.formComprar.Q1,this.val ue)\">\n";
$i=1;
//insertamos el titulo
$combo .= " <option value='" .$i. "'>Seleccione su talla.................</option>\n";
$artalla[$i]=$row_tallas['size'];

$i=2;
//Insertamos la primer talla
$combo .= " <option value='".$stock_actual;
$combo .= "'>".$row_tallas['size']."</option>\n";
$artalla[$i]=$row_tallas['size'];

//Insertamos el resto de tallas
while($row_tallas = mysql_fetch_array($result_tallas))
{
$query_carrito = "SELECT sum(products_quantity) as total FROM user_basket WHERE products_id='".$id."' AND products_size='".$row_tallas['size']."'";
$result_carrito = mysql_query($query_carrito, $this->link) or $this->_Error(mysql_error(), 'ERROR | DB_ERROR');
$row_carrito = mysql_fetch_array($result_carrito);
$stock_actual=$row_tallas['stock_actual']-$row_carrito['total'];

$i=$i+1;
$combo .= " <option value='".$stock_actual;
$combo .= "'>".$row_tallas['size']."</option>\n";
$artalla[$i]=$row_tallas['size'];

}


$oleole=1;

$combo .= "</select>\n";
echo $combo ;



CODE that ADD the data to the second combo:

<script language="JavaScript" type="text/javascript">

function addOpt(oCntrl, iPos, sTxt, sVal){

var selOpcion=new Option(sTxt, sVal);
eval(oCntrl.options[iPos]=selOpcion);




}

function cambia(oCntrl,valor){

while (oCntrl.length) oCntrl.remove(0);
{

var selObj = document.getElementById('ta');
var selIndex = selObj.selectedIndex;
var esta = selObj.options[selIndex].text
var txtTextObj = document.getElementById('txtText');
txtTextObj.value = selObj.options[selIndex].text;

if (valor ==0)
{
addOpt(oCntrl, 0, "AGOTADO.............................", "0");
}
else if (valor >=5)
{
addOpt(oCntrl, 0, "Seleccione la Cantidad..........", "0");
addOpt(oCntrl, 1, "1", "1");
addOpt(oCntrl, 2, "2", "2");
addOpt(oCntrl, 3, "3", "3");
addOpt(oCntrl, 4, "4", "4");
addOpt(oCntrl, 5, "5", "5");
}
else
{
addOpt(oCntrl, 0, "Seleccione la Cantidad..........", "0");
var i=1;
while (valor !=0) {

addOpt(oCntrl, i, i, i);
i = i + 1;
valor = valor - 1;
}
}

}

}
</script>
Jun 2 '07 #14
acoder
16,027 Expert Mod 8TB
Change the eval statement with the try...catch statement posted by ronnil, i.e. use the add method. Since IE uses a non-standard (as ever), you need the try/catch for it to work cross-browser. See the link I posted earlier which also explains this.
Jun 4 '07 #15
Change the eval statement with the try...catch statement posted by ronnil, i.e. use the add method. Since IE uses a non-standard (as ever), you need the try/catch for it to work cross-browser. See the link I posted earlier which also explains this.
I have changed my funtion to this. RESULT: works fine in IE but not in Firefox. I don't understand it it's so dificult?

function addOpt(oCntrl,iPos,sTxt,sVal)

{

var newOpt = document.createElement('option');
newOpt.value = iPos;
newOpt.text = sTxt;

if(sVal == undefined)
sVal = null;
try{

oCntrl.add(newOpt,sVal);

} catch(e) {

try{

oCntrl.add(newOpt);

} catch(e) {

alert('You have a sucky browser, please visit http://www.mozilla.org to get a proper one');

}

}

}
Jun 4 '07 #16
acoder
16,027 Expert Mod 8TB
I think you'll need to swap the iPos and sVal around. BTW, you don't need the 'sucky' alert!
Jun 4 '07 #17
I think you'll need to swap the iPos and sVal around. BTW, you don't need the 'sucky' alert!
i don't undestand what you mean with swap the ipos and sval.

????
Jun 4 '07 #18
acoder
16,027 Expert Mod 8TB
i don't undestand what you mean with swap the ipos and sval.

????
iPos is a number and sVal is a string. You're using them in the wrong places, e.g. the second argument of the add method expects a number, but you're giving it a string (sVal instead of iPos).
Jun 4 '07 #19
iPos is a number and sVal is a string. You're using them in the wrong places, e.g. the second argument of the add method expects a number, but you're giving it a string (sVal instead of iPos).

Nothing, do the same, work in IE but NOT in FF.

Please help.
Jun 5 '07 #20
Please i will make paypal donation who resolve the problem
Jun 5 '07 #21
acoder
16,027 Expert Mod 8TB
Have you tried this?
Expand|Select|Wrap|Line Numbers
  1.  function addOpt(oCntrl,iPos,sTxt,sVal) {
  2.           var newOpt = document.createElement('option');
  3.           newOpt.value = sVal;
  4.           newOpt.text = sTxt;
  5.  
  6.           if(iPos == undefined)
  7.               iPos = null;
  8.           try{
  9.               oCntrl.add(newOpt,iPos);
  10.           } catch(e) {
  11.               try{
  12.                   oCntrl.add(newOpt);
  13.                   } catch(e) {
  14.                       alert('Didn\'t work');
  15.                   }
  16.           }
  17.       }
Jun 5 '07 #22
mmm i thing the error was in another place.

The error console of FF say "selObj has no properties"

When i clic the error it take me to the folowing line in the "cambia" function.


var selIndex = selObj.selectedIndex;
Jun 5 '07 #23
Plater
7,872 Expert 4TB
Change the eval statement with the try...catch statement posted by ronnil, i.e. use the add method. Since IE uses a non-standard (as ever), you need the try/catch for it to work cross-browser. See the link I posted earlier which also explains this.
Don't make me even start with how bad FF is at maintaining standars. (You'd think they never even heard of w3.org)
Jun 5 '07 #24
acoder
16,027 Expert Mod 8TB
Don't make me even start with how bad FF is at maintaining standars. (You'd think they never even heard of w3.org)
Er, surely you mean IE?!
Jun 5 '07 #25
acoder
16,027 Expert Mod 8TB
mmm i thing the error was in another place.

The error console of FF say "selObj has no properties"

When i clic the error it take me to the folowing line in the "cambia" function.


var selIndex = selObj.selectedIndex;
Hah, no wonder. All that time, you're trying to access an element with an id of 'ta', but there is no element with an id of 'ta'! No, "name" does not equal "id" (except for IE!). If you add an id, then that error should go.
Jun 5 '07 #26
Er, surely you mean IE?!
i concur...surely you mean IE?!?!
Jun 5 '07 #27
Plater
7,872 Expert 4TB
i concur...surely you mean IE?!?!
Nope I ment what I said.
I just moved to firefox 2.0 (which told me "we don't do java anymore, sorry" which i thought was "funny") so maybe they have actually implemented some of the css standards. What are they on like 3? 4? firefox seemed to be stuck at 1.
Jun 6 '07 #28
drhowarddrfine
7,435 Expert 4TB
Plater,
The two most standards compliant browsers in the world are Firefox and Opera. They both run rings around IE which is nine years behind the W3C in standards compliance. If it doesn't work in Firefox then something is wrong with the code.

If you need help in determining where browsers stand with standards compliance, this link and this link serve me well and you probably need to spend a lot of time there.

If you are thinking IE does better with compliance, please visit the IEBlog site where lead developer, Chris Wilson, apologizes for IEs feable effort.
Jun 6 '07 #29
Plater
7,872 Expert 4TB
I generally try to use w3.org, since they ARE the standards people and not some 3rd party knock off site.
Jun 6 '07 #30
drhowarddrfine
7,435 Expert 4TB
Yes, but they don't show which browsers comply with the standard. Firefox is, by far, the most standards compliant browser, along with Opera. They are the only browsers you should initially test ANY markup and code in. Once it is working in these modern browsers, then you can adjust for IEs quirks and bugs. Generally, any code that works in Firefox will run anywhere, but you have NO assurances that code written for IE will run anywhere else.

btw, that link is hardly a 'knockoff site'. That implies they copy; he doesn't.
Jun 6 '07 #31
Hah, no wonder. All that time, you're trying to access an element with an id of 'ta', but there is no element with an id of 'ta'! No, "name" does not equal "id" (except for IE!). If you add an id, then that error should go.
GREAT!!! There was the problem. Yeaaaaaaaaaaahhhhhh hahahahahaha jojojojjojo jujjujjujujjuju

Thanks.
Jun 7 '07 #32
acoder
16,027 Expert Mod 8TB
GREAT!!! There was the problem. Yeaaaaaaaaaaahhhhhh hahahahahaha jojojojjojo jujjujjujujjuju

Thanks.
Yes, good job you finally got it. IE was at fault here.
Jun 8 '07 #33
acoder
16,027 Expert Mod 8TB
Don't make me even start with how bad FF is at maintaining standars. (You'd think they never even heard of w3.org)
For one thing, we have to code separately for IE.

Secondly, this problem was caused by IE. If you type document.getElementById(id), how on earth is that supposed to work with 'name' when there's no id. Completely non-standard.
Jun 8 '07 #34

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

Similar topics

1
by: Michelle Collier-Moore | last post by:
I have a form where the user selects a client name originally from a table and then proceeds to complete other details in a sub form. The users asked to see two pieces of information relating to...
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
4
by: Mike L | last post by:
Currently, when the user presses a letter key the combo box will go to the first item in the collection of the combo box starting with that letter. For example user presses on "R", and "R2F"...
1
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard....
10
by: Richard | last post by:
I have created a form which sets up a dataview. The form views one record at a time using a currencymanager. This works fine. All my text boxes bind. However I have a combo box which gets its...
10
by: lorirobn | last post by:
Hi, I have a form with several combo boxes, continuous form format, with record source a query off an Item Table. The fields are Category, Subcategory, and Color. I am displaying descriptions,...
9
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the...
7
by: badboybrown | last post by:
I know that this is an age old question and it has been approached a few times, but I've hit a wall and require some help. I have various combo boxes that contain values that are both "current"...
0
by: mollyf | last post by:
I've got a combo box that I want to bind a collection to. I got the error "Complex Data Binding accepts as a data source either an IList or an IListSource" so I tried using the BindingSource,...
2
by: dancole42 | last post by:
So I have a subform that lists the various items on a particular invoice. First, the user selects a product class from the Class dropdown. This is bound to the Class field in the InvioceLines...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.