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

autoselect all items in <SELECT> control is undone when form submits

I'm stuck trying to work with a HTML <SELECT> control and javascript
(similar to DualList but that control doesn't offer enough options to
totally control the text on the buttons and control, also I don't have
c# on this machine to try and modify it).. anyway...

I'm trying to get javascipt to select all items in a <SELECT> control
and submit the form to an asp.net page. For some reason when the link
is clicked, you can see the items all get selected, but then they are
somehow unselected as the form posts. Any idea? My Html and .net code
follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>test SELECT</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>

<form id="Form1" method="post" runat="server">

<table>
<tbody>
<tr>
<td>
<SELECT multiple size="20" name="ListBox2" id="ListBox2"
style="WIDTH:350px">
<OPTION selected value="Value 1">Text 1</OPTION>
<OPTION>Text 2</OPTION>
<OPTION>Text 3</OPTION>
<OPTION>Text 4</OPTION>
<OPTION>Text 5</OPTION>
<OPTION>Text 6</OPTION>
<OPTION>Text 7</OPTION>
<OPTION>Final option</OPTION>
</SELECT>
</td>
</tr>
<tr>
<td>
<asp:TextBox id="txtOut" runat="server" Columns="60" Rows="10"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<a href="#" onclick="javascript:selectListBox2();">click me</a>
&nbsp;
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</td>
</tr>
</tbody>
</table>

<script>
<!--
function selectListBox2()
{
var iLoop;
for (iLoop = 0; iLoop < document.Form1.ListBox2.length; iLoop++)
{
document.Form1.ListBox2[iLoop].selected = true;
}
document.Form1.submit();
}
// -->
</script>

</form>

</body>
</HTML>


Public Class test_DualList
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents txtOut As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim iLoopRows As Int16

If (IsPostBack) Then
txtOut.Text = Request.Form.Item("ListBox2")
Else
Button1.Attributes.Add("onclick",
"javascript:selectListBox2();")
End If

End Sub
End Class
Nov 18 '05 #1
1 2055
because your anchor is refreshing the page. try:

<a href="javascript:selectListBox2();">click me</a>

-- bruce (sqlwork.com)
"Mad Scientist Jr" <us*************@yahoo.com> wrote in message
news:7a**************************@posting.google.c om...
I'm stuck trying to work with a HTML <SELECT> control and javascript
(similar to DualList but that control doesn't offer enough options to
totally control the text on the buttons and control, also I don't have
c# on this machine to try and modify it).. anyway...

I'm trying to get javascipt to select all items in a <SELECT> control
and submit the form to an asp.net page. For some reason when the link
is clicked, you can see the items all get selected, but then they are
somehow unselected as the form posts. Any idea? My Html and .net code
follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>test SELECT</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>

<form id="Form1" method="post" runat="server">

<table>
<tbody>
<tr>
<td>
<SELECT multiple size="20" name="ListBox2" id="ListBox2"
style="WIDTH:350px">
<OPTION selected value="Value 1">Text 1</OPTION>
<OPTION>Text 2</OPTION>
<OPTION>Text 3</OPTION>
<OPTION>Text 4</OPTION>
<OPTION>Text 5</OPTION>
<OPTION>Text 6</OPTION>
<OPTION>Text 7</OPTION>
<OPTION>Final option</OPTION>
</SELECT>
</td>
</tr>
<tr>
<td>
<asp:TextBox id="txtOut" runat="server" Columns="60" Rows="10"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<a href="#" onclick="javascript:selectListBox2();">click me</a>
&nbsp;
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</td>
</tr>
</tbody>
</table>

<script>
<!--
function selectListBox2()
{
var iLoop;
for (iLoop = 0; iLoop < document.Form1.ListBox2.length; iLoop++)
{
document.Form1.ListBox2[iLoop].selected = true;
}
document.Form1.submit();
}
// -->
</script>

</form>

</body>
</HTML>


Public Class test_DualList
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents txtOut As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim iLoopRows As Int16

If (IsPostBack) Then
txtOut.Text = Request.Form.Item("ListBox2")
Else
Button1.Attributes.Add("onclick",
"javascript:selectListBox2();")
End If

End Sub
End Class

Nov 18 '05 #2

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

Similar topics

1
by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php...
2
by: Mad Scientist Jr | last post by:
I'm trying to get javascipt select all items in a HTML form <SELECT> control and submit the form to an asp.net page. For some reason when the link is clicked, you can see the items all get...
5
by: Charles Lavin | last post by:
Hi -- I have a table cell in which is placed a <SELECT> tag. The drop-down box has an excessive amount of whitespace below it, forcing the cell to adjust its height to accommodate this extra...
2
by: Joachim Bauer | last post by:
I'm using the code below to display a menu that opens when the mouse goes over the main menu item (try it in your browser to understand the behaviour). It uses "position:absolute" and a switch...
2
by: abs | last post by:
Hello everybody. A piece of html code: <form ... > <select ....> <option .... <option .... </select> <select ....>
6
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
7
by: lambertb | last post by:
Hi, is this possible to achieve this, and how? http://img217.imageshack.us/img217/779/derrrvw2.png thanks!
1
by: Eric | last post by:
Hello, I'm trying (without any success) to get the value of a disabled select control. From reviewing: http://www.w3.org/TR/html401/interact/forms.html#adef-disabled It doesn't sound like...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.