 |
| Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 2nd, 2004, 08:04 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
multiselect list box display selected problem
Hi,
I am using a multi select list box on a crowded screen,
I default the size to 1
onfocus I set the size to 5 (onfocus="this.size = 5;")
on leaving I reset it to 1 (onmouseout="this.size=1; return true;")
Unfortunately:( this resets the value to the first item in the
list box.
I need to display the first selected item.
How do I achieve this ?
(its probably a simple function but it currently eludes me )
|
|

March 2nd, 2004, 10:07 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
I tried this:
Code:
<html>
<body>
<select onmouseout="this.size=1; return true;" onmouseover="this.size=5" size=1>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</body>
</html>
and it had a really cool effect (I might have to use it...).
I changed onfocus to onmouseover... will this work for you?
Worked perfectly for me.
----------
---Snib---
----------
|
|

March 3rd, 2004, 09:44 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Snib,
I like the effect better than what I am doing, but it still does not solve the basic problem;
When I move the mouse out and the box returns to size 1, I want to see the first selected item, not the first Item in the list.
Thanks for the help
|
|

March 3rd, 2004, 10:49 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
This works fine:
Code:
<html><head><title>Select Size</title>
<script>
function changeSize(Listbox, Size)
{
Listbox.size = Size;
}
</script>
</head>
<body>
<select onmouseout="changeSize(this, 1);" onmouseover="changeSize(this, 5);">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</body>
</html>
but fails when the select is a MULTIPLE one. I've noticed they behave differently in other odd ways too. Have you noticed how the drop down arrow is different as well?
My suggestion, if you really need this feature, is to dynamically change the select box from multiple to single as you mouse out after storing the selected value(s) in an array and just setting the selected option to the first chosen one. On mouse over change it back to a multiple one. Change it back too multiple yet again and re-assign the values before submitting the form.
--
Joe
|
|

March 3rd, 2004, 04:59 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
If I understand correctly, your problem is that onmouseout, the first selection (in my example "1") is automatically selected. This does not happen to me, nor does the arrow change. Are you using Netscape or something? (I'm not, I'm using IE6).
This link works fine with me (it keeps the selected item selected onmouseout)
http://www.snibworks.com/examples/e001.html
----------
---Snib---
----------
|
|

March 3rd, 2004, 05:34 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Snib
I'm using Ie 6.0 too,
The problem I get is if I have a list of ten items. I put the mouse over the field and see five of them. If I click on (select) the fourth one, when I leave the field the field shrinks to one item and again shows the first item, which was not selected.
Of course if I select the top item of the five displayed it works fine.
I would like it to show the first Item selected. whenever I leave the field.
Peter
|
|

March 4th, 2004, 05:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Quote:
quote:Originally posted by Snib
If I understand correctly, your problem is that onmouseout, the first selection (in my example "1") is automatically selected. This does not happen to me, nor does the arrow change. Are you using Netscape or something? (I'm not, I'm using IE6).
This link works fine with me (it keeps the selected item selected onmouseout)
http://www.snibworks.com/examples/e001.html
----------
---Snib---
----------
|
Yes, but as I pointed out your select isn't set to multiple, you'll see it's very different.
--
Joe
|
|

March 4th, 2004, 11:25 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi guys,
This is the actual code I'm using:
<SELECT size="1" NAME="POLNTR" multiple
onmouseover="this.size = 4;"
onmouseout="this.size=1; return true;">
<OPTION SELECTED VALUE="ALL">All
<OPTION VALUE="0">0
<OPTION VALUE="1">1
<OPTION VALUE="2">2
<OPTION VALUE="3">3
<OPTION VALUE="4">4
<OPTION VALUE="5">5
<OPTION VALUE="6">6
<OPTION VALUE="7">7
<OPTION VALUE="8">8
<OPTION VALUE="9">9
<OPTION VALUE="10+">10+
</SELECT>
It may help show the problem.
|
|

March 4th, 2004, 01:44 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
All right! :D
http://www.snibworks.com/examples/e001.php
I'm sure there's probably a tidier way to do this, but this is what I found
----------
---Snib---
----------
|
|

March 4th, 2004, 02:45 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
   
Thanks
Works great, and gives me some new tags to investigate, thanks
Much Appreciated
 :D
|
|
 |