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

Help with function to determine listbox contents

P: n/a
Hi,

I was wondering if this is correct code for determine the contents of
a listbox. I'm particularly interested to know if the
sel1.options[i].valueOf() call will tell me the value of the item as
it loops through the for statement:

function listBoxContents(sel1)
{
var selLength1 = sel1.length;
var i;
var values;

for(i=0; i<=selLength1-1; i++)
{
values=sel1.options[i].valueOf() + ",";
}
var lastComma = values.lastIndexOf(',');
values = values.substring(0,lastComma);

return values;
}

May 3 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On May 3, 7:12 am, tks...@gmail.com wrote:
Hi,
function listBoxContents(sel1)
{
var selLength1 = sel1.length;
var i;
var values;

for(i=0; i<=selLength1-1; i++)
{
values=sel1.options[i].valueOf() + ",";
}
var lastComma = values.lastIndexOf(',');
values = values.substring(0,lastComma);

return values;}
function listBoxContents(sel1)
{
var selLength1 = sel1.options.length,i,values='';

for(i=0; i<selLength1; i++)
values+=sel1.options[i].value+ ",";
return values.slice(0,-1)
}

May 3 '07 #2

P: n/a
On May 3, 9:36 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
On May 3, 7:12 am, tks...@gmail.com wrote:
Hi,
function listBoxContents(sel1)
{
var selLength1 = sel1.length;
var i;
var values;
for(i=0; i<=selLength1-1; i++)
{
values=sel1.options[i].valueOf() + ",";
}
var lastComma = values.lastIndexOf(',');
values = values.substring(0,lastComma);
return values;}

function listBoxContents(sel1)
{
var selLength1 = sel1.options.length,i,values='';

for(i=0; i<selLength1; i++)
values+=sel1.options[i].value+ ",";
return values.slice(0,-1)

}


Thanks! Now say I want to hide this return value in hidden input, can
I say something like below:

function listBoxContents(sel1)
{
var selLength1 = sel1.options.length,i,values='';

for(i=0; i<selLength1; i++)
values+=sel1.options[i].value+ ",";
document.writeln("<input type='hidden' name='hiddenValues' value='"
+ values.slice(0,-1) + "'>");
}

May 3 '07 #3

P: n/a
tk****@gmail.com wrote:
Thanks! Now say I want to hide this return value in hidden input, can
I say something like below:

function listBoxContents(sel1)
{
var selLength1 = sel1.options.length,i,values='';

for(i=0; i<selLength1; i++)
values+=sel1.options[i].value+ ",";
document.writeln("<input type='hidden' name='hiddenValues' value='"
+ values.slice(0,-1) + "'>");
}
function listBoxContents(sel1)
{
var selLength1 = sel1.options.length,i,values='';

for(i=0; i<selLength1; i++)
values+=sel1.options[i].value+ ",";
var input=document.createElement("input");
input.name="hiddenValues";input.type="hidden";
input.value=values.slice(0,-1);
document.body.appendChild(input);
}

May 3 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.