function problems

H

hal

I'm creating an asp.net page using c# and javascript. I have three
different controls on the page, and only when all three have been
accessed i want an imagebutton to go from disabled to enabled and
change its image. I somewhat got it working. I'm able to change the
image and have the imagebutton go from disabled to enabled using one
control at a time, but can't figure out to have the button do this
only after all three controls have been accessed. Below is my code:

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>

<script type="text/javascript">
function SetImage()
{
if
((window.document.getElementById("TextBox1").attributes.length > 0) &&

(window.document.getElementById("DropDownList1").attributes.length >
0) &&

(window.document.getElementById("CheckBox1").attributes.length > 0))
{
document.all("ImageButton1").src = "Images/
enable.jpg";

window.document.getElementById("ImageButton1").disabled = false;
}
}

</script>

<form id="Form1" method="post" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Select A Location</asp:ListItem>
<asp:ListItem>Virginia</asp:ListItem>
<asp:ListItem>Florida</asp:ListItem>
<asp:ListItem>New York</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"
onkeyup="SetImage()"></asp:TextBox>
<br />
<br />
<asp:CheckBox ID="CheckBox1" onclick="SetImage()" Text="I
Agree" runat="server" />
<br />
<br />
<asp:ImageButton ID="ImageButton1" Enabled="False"
runat="server" ImageUrl="~/Images/disable.jpg" />
</form>
</body>
</html>

/////CODE BEHIND//////
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Attributes.Add("onchange", "SetImage()");
}
}
 
P

Peter Michaux

I'm creating an asp.net page using c# and javascript. I have three
different controls on the page, and only when all three have been
accessed i want an imagebutton to go from disabled to enabled and
change its image. I somewhat got it working. I'm able to change the
image and have the imagebutton go from disabled to enabled using one
control at a time, but can't figure out to have the button do this
only after all three controls have been accessed. Below is my code:

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

When posting to comp.lang.javascript it is best to post only HTML CSS
JavaScript as it is unlikely other contributors will know your
particular sever-side language and/or framework. For example, I have
no clue about C# or asp.net.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


XHTML is no good for the general web for many reasons. Two reasons are
Internet Explorer - the most popular browser - is an HTML-only browser
and Safari can stop parsing XHTML if it invalid. HTML 4.01
transitional is the most general purpose doctype (because of iframe
hacks.)

<URL: http://www.thewebcreator.net/2007/04/16/why-you-should-be-using-html-401-instead-of-xhtml/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>

<script type="text/javascript">
function SetImage()
{
if
((window.document.getElementById("TextBox1").attributes.length > 0) &&

If you limit your line length to 70 characters then it is likely
possible to post and have one reply without unintended line wraps.

[snip]

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top