Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple line text box .....Please help me for code!!

Status
Not open for further replies.

paragvshah

Programmer
Jan 11, 2001
109
IN
hi friends ,
I need your help for some javaScript code which has follwing functing.

I have two multiple line text boxes.
One of which contains multiple items, user has to select one or More otems from this box then there is a ADD or ADD ALL button to add selected or ALL feilds from first Multiline box and populate the other box.
Similarly he can choose any entered feild from Second Box and REMOVE it using remove button or can use REMOVE ALL option
to remove all the feilds from the second text box.

Can you tell me how can I do this .
It would ne very nice if you can either send me code or give me address of the site from where I can down load that code.

regards
Parag Shah
 
/*
pushall takes the following arguments:
from - a reference to a selectbox to move the items out of
to - a reference to a selectbox to move the items into
send - whether to actually send to the other box, or just remove from here
discard - should i remove them from the from argument
validate - an optional parameter to call a function that must return true or false
the item in question will be passed as an argument to this function

Note: you must also include pushSel to use this

*/

function pushAll(from,to,send,discard,validate)
{
fromar=from.options;fromlen=fromar.length;
for(var i=0;i<fromlen;i++)
{
fromar.selected=true;
}
pushSel(from,to,send,discard,validate||false)
}

/*
pushall takes the following arguments:
from - a reference to a selectbox to move the items out of
to - a reference to a selectbox to move the items into
send - whether to actually send to the other box, or just remove from here
discard - should i remove them from the from argument
validate - an optional parameter to call a function that must return true or false
the item in question will be passed as an argument to this function

Note: send or discard must be true or there is no point

*/

function pushSel(from,to,send,discard,validate)
{
var fromar,fromlen
validate=validate||function (){return true}
fromar=from.options;fromlen=fromar.length;
if(!send && !discard){top.status='pushSel: args 2&3 both false - no point';return true} //stay for val?not likely.
for(var i=0;i<fromlen;i++)
{
if(fromar==null){continue}
if(fromar.selected)
{
if(validate(fromar))
{
//do them jive
if(send)
{
to.add(new Option(fromar(i).text,fromar(i).value))
if(discard){from.remove(i--);}
}
else if(discard){from.remove(i--);}
}
else{continue}
}
else{continue}
}
//these lines below kill a very odd bug, try commenting them out,
//scrolling the list to the bottom, and choosing the top item!
from.style.visibility='hidden'
from.style.visibility='visible'
}

</script>

heres an example:

<select hidefocus ondblclick=&quot;pushSel(this,boxbottom,true,true)&quot; style=&quot;width:200px&quot; size=10 multiple id=&quot;boxtop&quot;>
<option value=&quot;tiger&quot;>Tiger Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
</select>

<br><br>
<button onClick=&quot;pushAll(boxtop,boxbottom,true,true)&quot;>All top to bottom</button>
<button onClick=&quot;pushSel(boxtop,boxbottom,true,true)&quot;>Selected top to bottom</button>
<button onClick=&quot;pushAll(boxbottom,boxtop,true,true)&quot;>All bottom to top</button>
<button onClick=&quot;pushSel(boxbottom,boxtop,true,true)&quot;>Selected bottom to top</button>
<br><br>

<select style=&quot;width:200px&quot; size=10 multiple id=&quot;boxbottom&quot;>

</select>
jared@eae.net -
 
TGML screwed up the first post. use this instead:

/*
pushall takes the following arguments:
from - a reference to a selectbox to move the items out of
to - a reference to a selectbox to move the items into
send - whether to actually send to the other box, or just remove from here
discard - should i remove them from the from argument
validate - an optional parameter to call a function that must return true or false
the item in question will be passed as an argument to this function

Note: you must also include pushSel to use this

*/

function pushAll(from,to,send,discard,validate)
{
fromar=from.options;fromlen=fromar.length;
for(var i=0;i<fromlen;i++)
{
fromar.selected=true;
}
pushSel(from,to,send,discard,validate||false)
}

/*
pushall takes the following arguments:
from - a reference to a selectbox to move the items out of
to - a reference to a selectbox to move the items into
send - whether to actually send to the other box, or just remove from here
discard - should i remove them from the from argument
validate - an optional parameter to call a function that must return true or false
the item in question will be passed as an argument to this function

Note: send or discard must be true or there is no point

*/

function pushSel(from,to,send,discard,validate)
{
var fromar,fromlen
validate=validate||function (){return true}
fromar=from.options;fromlen=fromar.length;
if(!send && !discard){top.status='pushSel: args 2&3 both false - no point';return true} //stay for val?not likely.
for(var i=0;i<fromlen;i++)
{
if(fromar==null){continue}
if(fromar.selected)
{
if(validate(fromar))
{
//do them jive
if(send)
{
to.add(new Option(fromar(i).text,fromar(i).value))
if(discard){from.remove(i--);}
}
else if(discard){from.remove(i--);}
}
else{continue}
}
else{continue}
}
//these lines below kill a very odd bug, try commenting them out,
//scrolling the list to the bottom, and choosing the top item!
from.style.visibility='hidden'
from.style.visibility='visible'
}

</script>

heres an example:

<select hidefocus ondblclick=&quot;pushSel(this,boxbottom,true,true)&quot; style=&quot;width:200px&quot; size=10 multiple id=&quot;boxtop&quot;>
<option value=&quot;tiger&quot;>Tiger Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
<option value=&quot;flute&quot;>Flute Man
<option value=&quot;dog&quot;>Dog Man
<option value=&quot;shark&quot;>Shark Man
</select>

<br><br>
<button onClick=&quot;pushAll(boxtop,boxbottom,true,true)&quot;>All top to bottom</button>
<button onClick=&quot;pushSel(boxtop,boxbottom,true,true)&quot;>Selected top to bottom</button>
<button onClick=&quot;pushAll(boxbottom,boxtop,true,true)&quot;>All bottom to top</button>
<button onClick=&quot;pushSel(boxbottom,boxtop,true,true)&quot;>Selected bottom to top</button>
<br><br>

<select style=&quot;width:200px&quot; size=10 multiple id=&quot;boxbottom&quot;>

</select>
jared@eae.net -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top