Connecting Tech Pros Worldwide Forums | Help | Site Map

Javascript code not working in IE but working in Mozilla firefox

Newbie
 
Join Date: Nov 2006
Posts: 1
#1: Dec 1 '06
Hi,

I am using this code to read the option values from a select option. I am getting the reference of that select option in arg1. Its working fine with mozilla firefox but not with Internet Explorer. It gives the lenth but failing to read the arguments(Shown in bold). It gives the alert Internet Explorer 4 for IE and Netscape 5 for Mozilla firefox for the alert in line 4. Please Suggest as soon as possible how I can read the values of the select option for IE. I shall be thankful.

function custom(arg,arg1)
if (arg == "custom")
{

var brow=((navigator.appName) + (parseInt(navigator.appVersion)));
alert("Browser" + brow);
var length = arg1.options.length;
alert("length" + length);
var str1 = "";

for(var i = 1;i < length-1; i++ )
{
str1 = str1 + arg1.options[i].value + ";" ;
}

alert(str1);
var url = "/futopt/globalrec-ajaysoni/webapp/jsp/welcome.jsp";
url = url + "?str=" + str1;
window.open(url,'welcome','width=300,height=200');
}
}

Newbie
 
Join Date: Dec 2006
Location: Karlstad / Sweden
Posts: 23
#2: Dec 4 '06

re: Javascript code not working in IE but working in Mozilla firefox


I don't understand what you're trying to do, but you're missing a "{" right after custom(arg,arg1). It will run in IE now. You are adding all values starting with the second and leaving the last one. Are you sure that is what you want?

If you want the selected value all you have to do is:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script language="javascript">
  4.             function custom(arg,arg1) {
  5.                 if (arg == "custom") {
  6.                     str1 = arg1.value;
  7.  
  8.                     var url = "/futopt/globalrec-ajaysoni/webapp/jsp/welcome.jsp";
  9.                     url = url + "?str=" + str1;
  10.                     window.open(url,'welcome','width=300,height=200'); 
  11.                 }
  12.             }
  13.         </script>
  14.     </head>
  15.     <body>
  16.         <select id="s_thing" onchange="custom('custom',this)">
  17.             <option value="One">One</optiin>
  18.             <option value="Two">Two</option>
  19.             <option value="Three">Three</optiin>
  20.         </select>
  21.     <body>
  22. </html>
Reply