473,396 Members | 2,010 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.

accessing elements added htmlselect using javascript

Dear All,

I placed a HtmlSelect control on a web page and set it to "Run at
Server", the
objective of this HtmlSelect control is that the client adds all his
accounts to a
text box, and because this is a client side operation(no server
intervention is required), I wrote the JavaScript below to add account
number
entered in a text box to the list control, this works fine, the client can
enter all his accounts to the html select control, the problem is that when
the page is posted to the server the code within the server returns no items
within the control so I have lstCustAcc.Items.Count = 0 even on the page it
contains some thing else >0, and I could not access any item within the
control.

summary:
the data added to the htmlselect control using the client javascript are
not accessable from C#.

PLEASE HELP.
function AddAcc()
{
var lstLen = document.Form1.lstCustAcc.length;
var selectedText = document.Form1.txtAccountNo.value;
var selectedValue = document.Form1.txtAccountNo.value;
var i;
var isNew = true;

if (lstLen != 0)
{
for (i = 0; i < lstLen; i++)
{
thisitem = document.Form1.lstCustAcc.options[i].text;
if (thisitem == selectedText)
{
isNew = false;
break;
}
}
}
if (isNew)
{
newoption = new Option(selectedText, selectedValue, false, false);
document.Form1.lstCustAcc.options[lstLen] = newoption;
}
document.Form1.lstCustAcc.selectedIndex=-1;
}

Thanks in advance,
Suhail

Nov 17 '05 #1
1 2253
All the HtmlSelect control does is generate the <SELECT ...><OPTION
....></SELECT> code in the HTML page. The HTML page knows nothing of
the HtmlSelect server control, and all that will happen when you
submit the page is what normally happens when you submit a HTML page
with a <SELECT> tag: i.e. it will just post the value of the selected
option within it.

What you will need to do is copy all of the values from the <SELECT>
<OPTION>s in to, say, a hidden text field. Then on the server you can
parse the posted value from the hidden text field.

However you submit the page, you will need to have something like:

<script>
function GetAccountDetails()
{
var lstAcconts=document.Form1.lstCustAcc;
var intIdx=0;
var strData='';

while ( intIdx < lstAccounts.length )
{
if ( intIdx > 0 )
strData+=',';

strData+=lstAccounts.options[intIdx].text;

intIdx++;
}

document.Form1.txtAccountNumbers.value=strData;
}
</script>
/* The following line must be inside the <FORM id="Form1"> ... </FORM>
tags */
<input type="hidden" id="txtAccountNumbers" value="">
Call the function from the <FORM> tag with

<FORM id="Form1" method="post" action="somepage.aspx"
onsubmit="GetAccountDetails();">
On the server, you could have the following (you'll have to convert
this to C#, cos I don't know it):
Dim strAccounts As String() = Split(Request.Form("txtAccountNumbers"),
",")
which will give you an array of the account numbers. If there is only
one element in the array, and it is an empty string, then there were
no account numbers.
"Suhail A, Salman" <su****@access2arabia.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
Dear All,

I placed a HtmlSelect control on a web page and set it to "Run at Server", the
objective of this HtmlSelect control is that the client adds all his accounts to a
text box, and because this is a client side operation(no server
intervention is required), I wrote the JavaScript below to add account number
entered in a text box to the list control, this works fine, the client can enter all his accounts to the html select control, the problem is that when the page is posted to the server the code within the server returns no items within the control so I have lstCustAcc.Items.Count = 0 even on the page it contains some thing else >0, and I could not access any item within the control.

summary:
the data added to the htmlselect control using the client javascript are not accessable from C#.

PLEASE HELP.
function AddAcc()
{
var lstLen = document.Form1.lstCustAcc.length;
var selectedText = document.Form1.txtAccountNo.value;
var selectedValue = document.Form1.txtAccountNo.value;
var i;
var isNew = true;

if (lstLen != 0)
{
for (i = 0; i < lstLen; i++)
{
thisitem = document.Form1.lstCustAcc.options[i].text;
if (thisitem == selectedText)
{
isNew = false;
break;
}
}
}
if (isNew)
{
newoption = new Option(selectedText, selectedValue, false, false); document.Form1.lstCustAcc.options[lstLen] = newoption;
}
document.Form1.lstCustAcc.selectedIndex=-1;
}

Thanks in advance,
Suhail

Nov 17 '05 #2

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

Similar topics

1
by: Jonathan | last post by:
Hi everyone, I have a problem with a HtmlSelect control that I am loading dynamically in javascript. Here is my code: <asp:DropDownList id="MyDropDownList1" onChange="LoadContent(this);"...
6
by: BK | last post by:
I'm having a really strange problem with and HtmlSelect server control (listbox) and a RequiredFieldValidator that I am trying to use to make sure that someone has items in the listbox. The way...
4
by: f_salazar | last post by:
English Version !! Hi !! I have a page with a Form, inside the form I have listbox with 'X' elements. Wend I submit the page, an ASP process inside the page have to read those elements and...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
4
by: nospam | last post by:
HtmlSelect has a method called OnServerChange that supposed to detect whether the control (select) has changed on a postback. This is not all that useful. It should be like the asp.net...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
6
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to...
3
by: judy.j.miller | last post by:
Does anyone know why i can't access a form element value using dot notation in firefox, when i'm in a function. Works ok in the body. I'm trying to do this: var FarTemp = faren.temp.value; I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.