rebuilding the combo options using javascript

R

Rashida

Hello,
We have a javascript function to sort the texts of the Combo box.
In this function, array is created to hold the option values and
sorting is done. After sorting, we are putting back the array values
to the combo options.

This is working fine if we have only value as the option attribute,
but if we have extra attributes other than value like CURRENT_RATE in
the option, we are not able to recreate this option attribute.
Because of this we are not able to retrieve CURRENT_RATE value after
select box sorting..

I have done some research work..but it is not working.

Here i am attaching the code.
Please suggest me some idea to overcome this problem.


The code starts here

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1>
<SELECT id=select1 name=select1>
<OPTION value='1'>vani</OPTION>
<OPTION value='2' ratecode='1.5' CURRENT_RATE=21>Kannan</OPTION>
<OPTION value='3' ratecode='1.6' CURRENT_RATE=22
ui='ie'>Sindhoor</OPTION>
<OPTION value='4' ratecode='1.7' CURRENT_RATE=23 df='45'
er='qw'>Tara</OPTION>
</SELECT>


<SCRIPT LANGUAGE=javascript>
<!--
alert(form1.select1.options[1].current_rate)
sortSelect(form1.select1)
alert(form1.select1.options[1].current_rate)
/*===================================================================
FUNCTION NAME : compareText()
ARGUMENTS (INPUT) :
The two text values to be sorted
ARGUMENTS (OUTPUT) :
1 or 0 depending on which value is greater
===================================================================*/
function compareText (option1, option2) {
return option1.text.toLowerCase() < option2.text.toLowerCase() ? -1
:
option1.text.toLowerCase() > option2.text.toLowerCase() ? 1 : 0;
}

/*===================================================================
FUNCTION NAME : sortSelect()
ARGUMENTS (INPUT) :
Select box to be sorted and the the compareFunction to be
called(optional)
ARGUMENTS (OUTPUT) :
sorted values of the Select box
===================================================================*/
function sortSelect (select, compareFunction)
{
if (!compareFunction)
compareFunction = compareText;

var options = new Array (select.options.length);

for (var i = 0; i < options.length; i++)
{
if(select.options.attributes.length>82)
{
var maxAtr = 82
var extraAtr = ""
for(var j=1;j<=(select.options.attributes.length-maxAtr);j++)
{
if(j==1)
{
extraAtr = select.options.attributes[(82)]
}
else
{
extraAtr = extraAtr+","+select.options.attributes[(81+j)]
}
}
alert(extraAtr)

options =
new Option (
select.options.text,
select.options.value,
select.options.defaultSelected,
select.options.selected,
extraAtr
);
}
else
{
options =
new Option (
select.options.text,
select.options.value,
select.options.defaultSelected,
select.options.selected
);
}
}

options.sort(compareFunction);

select.options.length = 0;

for (var i = 0; i < options.length; i++)
{
select.options = options;
}
alert(select.options.attributes.length)
}





//-->
</SCRIPT>

</FORM>
</BODY>
</HTML>

Ends here

Waiting for the kind replies

Thanks & Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top