473,770 Members | 4,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Item s.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.leng th;
var selectedText = document.Form1. txtAccountNo.va lue;
var selectedValue = document.Form1. txtAccountNo.va lue;
var i;
var isNew = true;

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

Thanks in advance,
Suhail

Nov 17 '05 #1
1 2272
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 GetAccountDetai ls()
{
var lstAcconts=docu ment.Form1.lstC ustAcc;
var intIdx=0;
var strData='';

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

strData+=lstAcc ounts.options[intIdx].text;

intIdx++;
}

document.Form1. txtAccountNumbe rs.value=strDat a;
}
</script>
/* The following line must be inside the <FORM id="Form1"> ... </FORM>
tags */
<input type="hidden" id="txtAccountN umbers" value="">
Call the function from the <FORM> tag with

<FORM id="Form1" method="post" action="somepag e.aspx"
onsubmit="GetAc countDetails(); ">
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.F orm("txtAccount Numbers"),
",")
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****@access2 arabia.com> wrote in message
news:u0******** ******@TK2MSFTN GP12.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.Item s.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.leng th;
var selectedText = document.Form1. txtAccountNo.va lue;
var selectedValue = document.Form1. txtAccountNo.va lue;
var i;
var isNew = true;

if (lstLen != 0)
{
for (i = 0; i < lstLen; i++)
{
thisitem = document.Form1. lstCustAcc.opti ons[i].text;
if (thisitem == selectedText)
{
isNew = false;
break;
}
}
}
if (isNew)
{
newoption = new Option(selected Text, selectedValue, false, false); document.Form1. lstCustAcc.opti ons[lstLen] = newoption;
}
document.Form1. lstCustAcc.sele ctedIndex=-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
381
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);" runat="server"> <asp:ListItem value="0">&nbsp;</asp:ListItem> <asp:ListItem value="1">MyChoice1</asp:ListItem> <asp:ListItem value="2">MyChoice2</asp:ListItem> </asp:DropDownList>
6
2161
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 that the HtmlSelect is populated is via a combination of client-side javascript and another aspx page (launched by the javascript). Anyway, everything seems to work just fine in terms of populating the HtmlSelect. However, when I postback the...
4
2315
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 then save them in a database. I try Request.Form("listbox") but doesnt work !
6
2746
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 called "form1", and I have selects called "PORTA", "PORTB" ... etc...
4
2667
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 control, DropDownList, that initiates a postback when the option, AutoPostBack is set to true...so you can either have it postback when the user changes it immediately or not do anything when the user changes it.
1
3139
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 elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
6
10423
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 group by using a two dimensional array. <form name=msgs>
3
10521
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 can get at the value using the array method, the getelements by id method, and the bracket-with-the-element-name in it method. But the dot notation doesn't work, in firefox, in the function (which i have in the head).
0
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.