Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > What is the problem? JavaScript - ListBox

Reply
Thread Tools

What is the problem? JavaScript - ListBox

 
 
Steven M
Guest
Posts: n/a
 
      02-07-2005
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();
}
 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      02-07-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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();
> }



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox item added with client scripts not submitting with ASP:Listbox Simon Prince ASP .Net 2 10-19-2004 04:11 PM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM
click listbox and refresh another listbox DC Gringo ASP .Net 0 04-06-2004 02:13 AM
add items from one listbox to other listbox from javascript mc Javascript 0 12-02-2003 08:23 PM
Re: now desparate! - 1st listbox contents disappears when 2nd listbox appears? blenderdude ASP .Net 0 08-03-2003 10:18 PM



Advertisments