473,385 Members | 1,720 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,385 software developers and data experts.

how to define javascript workable across browsers particularly innertext

hi
this particular piece of code is not working in netscape.
pls help me
function getList(listfrom, listto){
var currSelect = document.forms["actionmaster"].elements[listfrom];
var strid = "";
for (i = 0; i < currSelect.options.length; i++)
{
if (strid.length > 0)
{
strid = strid + "," + currSelect.options(i).innerText;
}
else
{
strid = currSelect.options(i).innerText;
}
}
document.forms["actionmaster"].elements[listto].value = strid;
return (strid == '' ? false : true);

}

How do i make this browser compatible..........?

thanx in anticipation

manu
Jul 23 '05 #1
1 1456
On 2 Apr 2004 06:32:21 -0800, Manu Ashok <ma********@yahoo.com> wrote:
this particular piece of code is not working in netscape.
That's because you're using IE syntax and proprietary Microsoft features.
function getList(listfrom, listto){
var currSelect = document.forms["actionmaster"].elements[listfrom];
var strid = "";
for (i = 0; i < currSelect.options.length; i++)
{
if (strid.length > 0)
{
strid = strid + "," + currSelect.options(i).innerText;
}
else
{
strid = currSelect.options(i).innerText;
}
}
document.forms["actionmaster"].elements[listto].value = strid;
return (strid == '' ? false : true);
}

How do i make this browser compatible..........?


I would re-write it like this:

function getList( listFrom, listTo )
{
var form = document.forms[ 'actionmaster' ];
var select = form.elements[ listFrom ];
var t = '';

for( var i = 0, n = select.length; i < n; ++i )
{
if( t.length ) // t is not zero-length
{
t += ',' + select.options[ i ].text;
}
else
{
t = select.options[ i ].text;
}
}
form.elements[ listTo ].value = t;
return t.length;
}

Notice that you should use brackets, not parentheses, to subscript a
collection (options is a collection property, not a method), and that the
HTMLOptionElement.text property will return the text between the opening
and closing OPTION tags, and that innerText isn't needed at all.

Finally, I know that "return t.length" will return a number. However, if
it is zero, it will evaluate to boolean false, or true otherwise. This
means you can write:

if( getList(...) ) {
// t was not an empty string
} else {
// t was an empty string
}

If you would rather return a boolean value from the function, use either

return !!t.length;

or

return( '' != t );

Using the conditional tertiary operator is overkill for such a simple
conversion.

Mike
In future, please don't indent your code from the left margin so much: it
causes extensive wrapping. Also, use two or four spaces for block
indentation, not tabs.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Bob Smith | last post by:
Hi all I have a page which contains a form. I want a customized button with an image for the submit button, and when the submit button has been clicked send the form to the perl script. Now the...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
4
by: bboyle18 | last post by:
Hi, I am working with a table sorting script which can be found here http://www.workingwith.me.uk/articles/scripting/standardista_table_sorting This script works very nicely, but when there is a...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.