473,738 Members | 7,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events not firing (Clearly I'm doing something wrong)

Here's the relevant XHTML:

-------------------------------------------------------------------------------------

<dl>
<dt>Add...</dt>
<dd><label for="radSection " ><input type="radio" id="radSection "
runat="server" value="1" /> Section</label>
<label for="radCategor y"><input type="radio" id="radCategory " runat="server"
value="2" /> Category</label></dd>

<dt><label for="selSection s">Add to</label></dt>
<dd><select id="selSections " runat="server" /></dd>

<dt><label for="txtName">N ame</label></dt>
<dd><input type="text" runat="server" id="txtName" /></dd>

<dt><label for="selDefault Article">Defaul t Article</label></dt>
<dd><select id="selDefaultA rticle" runat="server" /></dd>
</dl>

<div>
<button id="btnAdd">Add </button>
</div>

<script src="../scripts/Categories.js" type="text/javascript"></script>

-------------------------------------------------------------------------------------

And here's the script:

-------------------------------------------------------------------------------------

var radSection;
var radCategory;
var selSections;
var btnAdd;
document.onload = function() {
radSection = document.getEle mentById("radSe ction");
radCategory = document.getEle mentById("radCa tegory");
selSections = document.getEle mentById("selSe ctions");
btnAdd = document.getEle mentById("btnAd d");
radSection.oncl ick = function() {
selSections.Ena bled = false;
btnAdd.innerHTM L = "Add Section";
}
radCategory.onc lick = function() {
selSections.Ena bled = true;
btnAdd.innerHTM L = "Add Category";
}
}
var radSection;
var radCategory;
var selSections;
var btnAdd;
document.onload = function() {
radSection = document.getEle mentById("radSe ction");
radCategory = document.getEle mentById("radCa tegory");
selSections = document.getEle mentById("selSe ctions");
btnAdd = document.getEle mentById("btnAd d");
radSection.oncl ick = function() {
selSections.Ena bled = false;
btnAdd.innerHTM L = "Add Section";
}
radCategory.onc lick = function() {
selSections.Ena bled = true;
btnAdd.innerHTM L = "Add Category";
}
}

-------------------------------------------------------------------------------------

Firefox nor IE report any script errors, yet I can't see why it isn't
working. Any ideas?

Thanks

--
-David
Dec 5 '05 #1
4 1579
David R wrote:
Here's the relevant XHTML:

-------------------------------------------------------------------------------------
You could start by writing valid (X)HTML:
<dl>
<dt>Add...</dt>
<dd><label for="radSection " ><input type="radio" id="radSection "
runat="server" value="1" /> Section</label>
There is no 'runat' attribute for any HTML element. Having a single
radio button in a radio group means that once it is selected, it can't
be unselected.

<label for="radCategor y"><input type="radio" id="radCategory " runat="server"
value="2" /> Category</label></dd>
Same advice for this radio button. Users will end up with both
selected and can't deselect one.


<dt><label for="selSection s">Add to</label></dt>
<dd><select id="selSections " runat="server" /></dd>
A select element must have at least one option and a closing tag.


<dt><label for="txtName">N ame</label></dt>
<dd><input type="text" runat="server" id="txtName" /></dd>

<dt><label for="selDefault Article">Defaul t Article</label></dt>
<dd><select id="selDefaultA rticle" runat="server" /></dd>
A select element must have at least one option and a closing tag.

</dl>

<div>
<button id="btnAdd">Add </button>
</div>

<script src="../scripts/Categories.js" type="text/javascript"></script>

-------------------------------------------------------------------------------------

And here's the script:

-------------------------------------------------------------------------------------

var radSection;
var radCategory;
var selSections;
var btnAdd;
There is no need for these to be global.

document.onload = function() {
You are looking for window.onload.

radSection = document.getEle mentById("radSe ction");
radCategory = document.getEle mentById("radCa tegory");
selSections = document.getEle mentById("selSe ctions");
btnAdd = document.getEle mentById("btnAd d");
radSection.oncl ick = function() {
selSections.Ena bled = false;
selSections is a select element, it does not have an 'Enabled'
attribute. What do you expect to happen?

btnAdd.innerHTM L = "Add Section";
}
radCategory.onc lick = function() {
selSections.Ena bled = true;
btnAdd.innerHTM L = "Add Category";
}
} [...]
-------------------------------------------------------------------------------------

Firefox nor IE report any script errors, yet I can't see why it isn't
working. Any ideas?


Firefox does report an error. When you click on the radio buttons, it
says btnAdd is null - it is not added to the document because of the
invalid HTML.


--
Rob
Dec 5 '05 #2
>> <dd><label for="radSection " ><input type="radio" id="radSection "
runat="server" value="1" /> Section</label>


There is no 'runat' attribute for any HTML element. Having a single
radio button in a radio group means that once it is selected, it can't
be unselected.


"runat" is .NET, and has something to do with postback.

Far as I can tell.NET makes it difficult, at best, to write totally
valid HTML...

Dec 6 '05 #3
"Tony" <to****@dslextr eme.com> writes:
"runat" is .NET, and has something to do with postback.

Far as I can tell.NET makes it difficult, at best, to write totally
valid HTML...


You are not supposed to. What you are writing is ASP, which appears to
be an extension of HTML that is interpreted by the server. It should
be possible to send only valid HTML to the client (although I wouldn't
be surprised if it didn't anyway).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Dec 6 '05 #4
*cough*

The runat="server" attribute just makes the element programatticall y
accessible via inherited classes. The output is 100% valid XHTML.

ASP.NET also converts <select runat="server" /> to <select id="foo"
name="foo"></select>

....What I was posting, was my ASPX source, not my XHTML.

When you execute it, this is produced:

--------------------------------------------------------

<form id="Form" method="post" action="/AMS/Admin/Pages/Categories.aspx ">
<div><input type="hidden" name="__VIEWSTA TE"
value="dDwtMTA5 MzAzMDIwMDt0PDt sPGk8Mj47aTw0Pj s+O2w8dDxwPGw8V GV4dDs+O2w8XDxk bFw+Clw8ZHRcPkZ lYXR1cmVzXDwvZH RcPgpcPGRkXD4wX DwvZGRcPlw8L2Rs XD4KOz4+Ozs+O3Q 8O2w8aTw3Pjs+O2 w8dDx0PDtwPGw8a TwwPjs+O2w8cDxG ZWF0dXJlczsxPjs +Pjs+Ozs+Oz4+Oz 4+O2w8cmFkU2Vjd GlvbjtyYWRDYXRl Z29yeTs+Pg=="
/></div>

<dl>
<dt>Add...</dt>

<dd><label for="radSection " ><input value="1" name="" id="radSection "
type="radio" /> Section</label>
<label for="radCategor y"><input value="2" name="" id="radCategory "
type="radio" checked="checke d" /> Category</label></dd>

<dt><label for="selSection s">Add to</label></dt>
<dd><select name="selSectio ns" id="selSections ">
<option value="1">Featu res</option>
</select></dd>
<dt><label for="txtName">N ame</label></dt>
<dd><input name="txtName" id="txtName" type="text" size="30"
maxlength="50" /></dd>

<dt><label for="txtUrlName ">URL Name</label></dt>
<dd><input name="txtUrlNam e" id="txtUrlName " type="text" size="30"
maxlength="50" /></dd>

<dt><label for="selDefault Article">Defaul t Article</label></dt>
<dd><select name="selDefaul tArticle" id="selDefaultA rticle">
</select></dd>

<dt><label for="selPaging" >Default Paging</label></dt>

<dd><select name="selPaging " id="selPaging" >
<option value="5">5 Articles per list</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>

<option value="30">30</option>
<option value="50">50</option>
<option value="100">100 </option>
</select></dd>

<dt><label for="selType">R ender Type</label></dt>
<dd><select name="selType" id="selType">
<option value="1">Artic les (Normal view)</option>

<option value="2">Files (Slimline view)</option>
<option value="4">News (Full Article in list)</option>
</select></dd>

</dl>

<div>
<button id="btnAdd">Add </button>
</div>

<script src="../scripts/Categories.js" type="text/javascript"></script>
</form>
--------------------------------------------------------

Which is valid :)

And ASP.NET doesn't hinder one's ability to outout valid XHTML, all you need
to do is extend the base form and page classes, and ASP isn't an extension
of HTML.

Anyway, I made the changes to the *.js file and now it works like this:

--------------------------------------------------------

var radSection;
var radCategory;

var selSections;
var selPaging;
var selType;

var btnAdd;

window.onload = getElements();

function getElements() {

radSection = document.getEle mentById("radSe ction");
radCategory = document.getEle mentById("radCa tegory");

selSections = document.getEle mentById("selSe ctions");
selPaging = document.getEle mentById("selPa ging");
selType = document.getEle mentById("selTy pe");

btnAdd = document.getEle mentById("btnAd d");

radSection.oncl ick = function() {

selSections.dis abled = true;
selPaging.disab led = true;
selType.dsiable d = true;
btnAdd.innerHTM L = "Add Section";
}

radCategory.onc lick = function() {

selSections.dis abled = false;
selPaging.disab led = false;
selType.dsiable d = false;
btnAdd.innerHTM L = "Add Category";
}

}
--------------------------------------------------------
Dec 6 '05 #5

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

Similar topics

1
1749
by: Quimbly | last post by:
My KeyDown / KeyUp / KeyPress events are not firing; I can't figure out what I'm doing wrong. The code I'm using is basically straight from the manual. "this" refers to my Windows.Forms.Form object. this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); this.KeyPress += new
14
12140
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming years namespace MyNamespac public delegate void MyDel() public class MyBase public virtual...
1
8163
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
3
2299
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace WebApplication1 { using System;
30
3650
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment it seems to me that Microsoft has developed similar functionality via two keywords. I do understand that an event offers better encapsulation as the underlying delegate is private, but is that all ? -- Regards
0
1209
by: RobKinney1 | last post by:
Hello, One of our C# apps (2.0) depends on a few events. One of them being DocumentComplete. Well, everything works fine with users that have IE 6 installed on their computers. But we noticed here in testing that if we have IE 7 installed, these events don't even fire in our application. We also tried using the DownloadComplete event but that is not firing either. We uninstalled IE 7 and reverted to 6. Then everything worked...
5
2812
by: =?Utf-8?B?VmFubmk=?= | last post by:
Hi, I have a component where I need to have thread-safe access to a list. Operations on the list are done in critical sections (lock (lockObject) { ... } ) in the usual way, to make sure that no other thread will modify the list while operations are running. However, I at the end of the critical section, I need to fire an OnChange type of event, publishing the changed list item as part of my custom EventArgs. I want to be certain that...
4
2044
by: Joergen Bech | last post by:
I sometimes use delegates for broadcasting "StateChanged" events, i.e. if I have multiple forms and/or controls that need updating at the same time as the result of a change in a global/common object, I keep local references to this object in each UI object, e.g. Private WithEvents _tools As RepeatTools and catch messages in an event handler like this:
1
3144
by: BahatiSiD | last post by:
Hello! I have a class instance that fires events and they are handled in a form. I believe this kind of event is called trivial: public: delegate void CpuStepEventHandler(Object^ sender, CpuStepEventArgs^ e); public: event CpuStepEventHandler^ CpuStepEvent; protected: virtual void OnCpuStepEvent(CpuStepEventArgs^ e) { //if(CpuStepEvent != nullptr) CpuStepEvent(this, e);
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
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
9208
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
8210
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...
0
6053
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
4570
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...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2745
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.