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

What is the problem? JavaScript - ListBox

Hello!!!

I dont know what is the problem!!! I am desperate!!! I want to put
enabled = false a button when in ListBox has selected more than a
item.

this is the javascript.
it dosen't Work!!!!

<script language =javascript>
function JavaListBox()
{
var Contador = 0;
for (var i=0;i< document.all('ListBox1').options.length;i++)
{
if (document.all('ListBox1').options[i].selected == true)
{
Contador++;
}
}
if (Contador > 1)
{
document.all('btnMio').disabled = true;
}
else
{
document.all('btnMio').disabled = false;
}
}
</script>
here is the real code (codebehind)
private void Page_Load(object sender, System.EventArgs e)
{
this.RegisterStartupScript("JListBox",JavaScriptLi stBox());
}

private void ListBox1_PreRender(object sender, System.EventArgs e)
{
ListBox1.Attributes.Add("OnClick", "JavaListBox()");
}
private string JavaScriptListBox()
{
StringBuilder strMetodo = new StringBuilder();
strMetodo.Append("<script language=\"javascript\">");
strMetodo.Append("function JavaListBox(){");
strMetodo.Append("var Contador = 0;");
strMetodo.Append("for (var i=0;i<
document.all('ListBox1').options.length;i++)");
strMetodo.Append("{");
strMetodo.Append("alert('Entro For');");
strMetodo.Append("if (document.all('ListBox1').options[i].selected ==
true)");
strMetodo.Append("{");
strMetodo.Append("Contador++;");
strMetodo.Append("}");
strMetodo.Append("}");
strMetodo.Append("if (Contador > 1){ document.all('btnMio').disabled =
true}");
strMetodo.Append("else {document.all('btnMio').disabled = false}");
strMetodo.Append("}");
strMetodo.Append("</script>");
return strMetodo.ToString();
}
Nov 19 '05 #1
1 2098
You probably want to use the onChange event instead of onClick. It'll work
with OnClick but oddly (only when the select is clicked). That's assuming
you have all the right id's

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Steven M" <sm******@gmail.com> wrote in message
news:b4**************************@posting.google.c om...
Hello!!!

I dont know what is the problem!!! I am desperate!!! I want to put
enabled = false a button when in ListBox has selected more than a
item.

this is the javascript.
it dosen't Work!!!!

<script language =javascript>
function JavaListBox()
{
var Contador = 0;
for (var i=0;i< document.all('ListBox1').options.length;i++)
{
if (document.all('ListBox1').options[i].selected == true)
{
Contador++;
}
}
if (Contador > 1)
{
document.all('btnMio').disabled = true;
}
else
{
document.all('btnMio').disabled = false;
}
}
</script>
here is the real code (codebehind)
private void Page_Load(object sender, System.EventArgs e)
{
this.RegisterStartupScript("JListBox",JavaScriptLi stBox());
}

private void ListBox1_PreRender(object sender, System.EventArgs e)
{
ListBox1.Attributes.Add("OnClick", "JavaListBox()");
}
private string JavaScriptListBox()
{
StringBuilder strMetodo = new StringBuilder();
strMetodo.Append("<script language=\"javascript\">");
strMetodo.Append("function JavaListBox(){");
strMetodo.Append("var Contador = 0;");
strMetodo.Append("for (var i=0;i<
document.all('ListBox1').options.length;i++)");
strMetodo.Append("{");
strMetodo.Append("alert('Entro For');");
strMetodo.Append("if (document.all('ListBox1').options[i].selected ==
true)");
strMetodo.Append("{");
strMetodo.Append("Contador++;");
strMetodo.Append("}");
strMetodo.Append("}");
strMetodo.Append("if (Contador > 1){ document.all('btnMio').disabled =
true}");
strMetodo.Append("else {document.all('btnMio').disabled = false}");
strMetodo.Append("}");
strMetodo.Append("</script>");
return strMetodo.ToString();
}

Nov 19 '05 #2

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

Similar topics

2
by: Ralph Freshour | last post by:
I want to write a listbox sized to 8 rows - I want to show summaries in this listbox and when an item is selected, below I want to show the details of the summary - I can trap a javascript event...
4
by: Nevyn Twyll | last post by:
I have a web form, with c# code-behind. I have a listbox on the form, bound to a dataset. I want to have 2 buttons/hyperlinks/etc. beside the listbox. When they are clicked, I want to launch a...
3
by: Ryan Taylor | last post by:
Hello. I have an application where I need the user to be able to add items to a listbox. I've implemented this via javascript. The listbox is an <asp:ListBox>. However, when the user submits the...
1
by: deepak | last post by:
hi , i have 2 listbox and 2 buttons like add and remove, both listbox have multiple selection true so that i can either add or remove multiple selected items. the first listbox is populated with...
6
by: hardik | last post by:
hi friends i am very new to java script.if anyone can help me out then i will be thankful. i am using php and mysql in my learning project and i have two list boxes,now whenever user presses...
3
by: Gummy | last post by:
Hello, I have an ASPX page on which I place a UserControl 15 times (they only need to be static controls on the page). This UserControl is a set of two listboxes with radiobuttons above the...
3
by: Aamir Ghanchi | last post by:
Hi, I am wondering why the <%= % is not working when I use it to pass the clientid to a javascrip function from the aspx declaration code. Say, I have a listbox webcontrol and from its...
2
archulu
by: archulu | last post by:
hai this archulu Any one help to me, in my project i am using Domapi script for creating Listbox. the main problem is i am creating one button, when that button clicking Listbox(Domapi) was...
1
by: Jeff | last post by:
hi asp.net 3.5 (project upgraded from asp.net 2.0). are using vwd2008 express now This is my first ajax attempt. The code below shows a TextBox and a ListBox. The idea I was trying to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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,...

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.