473,898 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing checkbox in a javascript.

This has to be easy, but I'm at a loss.

In an externally linked js, I create a checkbox using innerHTML. How do I
test the value or test to see if it's checked while still within the js?

--
Ed Jay (remove M to respond by email)
Jan 13 '06 #1
5 6447
Danny <da*******@blue bottle.com> wrote:
Check at http://www.javascriptkit.com/javatut...diocheck.shtml .

Thanks. I just finished solving the problem. Using js, I dynamically
create a checkbox in a display-toggled (display:none/"") container and
then detect the state of the checkbox. It didn't play when I create the
checkbox using innerHTML, but it works with the checkbox permanently
written to the document in the toggled container.

--
Ed Jay (remove M to respond by email)
Jan 15 '06 #3
Ed Jay wrote:
This has to be easy, but I'm at a loss.

In an externally linked js, I create a checkbox using innerHTML. How do I
test the value or test to see if it's checked while still within the js?


Get a reference to the checkbox and determine the value of its 'checked'
attribute:
<form action="">
<div id="divA">
</div>
</form>

<script type="text/javascript">
function insertCheckbox( )
{
var h = '<input type="checkbox" name="check01" checked>';
document.getEle mentById('divA' ).innerHTML = h;
alert(document. forms[0].check01.checke d);
}
insertCheckbox( );
</script>
It worked OK in Safari and Firefox, but I would not guarantee it to work in
all browsers.

--
Rob
Jan 15 '06 #4
RobG said the following on 1/15/2006 12:44 AM:
Ed Jay wrote:
This has to be easy, but I'm at a loss.

In an externally linked js, I create a checkbox using innerHTML. How do I
test the value or test to see if it's checked while still within the js?

Get a reference to the checkbox and determine the value of its 'checked'
attribute:
<form action="">
<div id="divA">
</div>
</form>

<script type="text/javascript">
function insertCheckbox( )
{
var h = '<input type="checkbox" name="check01" checked>';
document.getEle mentById('divA' ).innerHTML = h;
alert(document. forms[0].check01.checke d);
}
insertCheckbox( );
</script>
It worked OK in Safari and Firefox, but I would not guarantee it to work
in all browsers.


Firefox, Opera 7/8/9 and IE6 on WinXP all give a true alert so you can
say it works there :)

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 15 '06 #5
RobG <rg***@iinet.ne t.au> wrote:
Ed Jay wrote:
This has to be easy, but I'm at a loss.

In an externally linked js, I create a checkbox using innerHTML. How do I
test the value or test to see if it's checked while still within the js?


Get a reference to the checkbox and determine the value of its 'checked'
attribute:
<form action="">
<div id="divA">
</div>
</form>

<script type="text/javascript">
function insertCheckbox( )
{
var h = '<input type="checkbox" name="check01" checked>';
document.getEle mentById('divA' ).innerHTML = h;
alert(document. forms[0].check01.checke d);
}
insertCheckbox( );
</script>
It worked OK in Safari and Firefox, but I would not guarantee it to work in
all browsers.


It works fine in Opera 8.5, too. That's essentially what I had, except I'm
not triggering an alert, I'm triggering a conditional statement. Unless
the element named 'check01' already exists, it can't be checked for state,
and the script fails. I coded the button into the document in a
display:none/"" container.

Triggering an alert doesn't tell the story, at least in this case. :-)

--
Ed Jay (remove M to respond by email)
Jan 15 '06 #6

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

Similar topics

9
4656
by: Phil Powell | last post by:
I am producing a form using PHP on the back end and Javascript on the front end. The resulting script will come to the browser as follows: <script> <!-- function selectAll() { moveElement = eval("document.imageForm.move" + ""); alert(moveElement); if (document.imageForm.select_all.checked) {
0
2138
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
5
9171
by: Leo J. Hart IV | last post by:
Hello, I'm hoping someone can help me out. I was wondering if the Enabled property of a CheckBox or RadioButton server control is stored in the ViewState. If not, is there some way to to add this property to ViewState? If needed, I can give you more info on exactly what I'm trying to do. Thanks,
5
3676
by: DotNetJunkies User | last post by:
1. i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis.... 2. after population there should be validation in checkboxlist..... that is if user clicks a button wihout checking any one of them(i.e. at least one shuld be checked) ... alerat message shouls come on the form....... these 2 steps should be...
2
14662
by: UJ | last post by:
Is there a way with a asp:checkbox to run a JavaScript to display/hide text/input on the screen without doing a postback? I also need to be able to access the stuff at the server so I need to have run=server with it. TIA - Jeff.
34
3859
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript function needs to run and validate all the checkboxes on my form and make sure none of them are unchecked. I suck at Javascript and my problem is 2fold. I have the following code that constructs the checkbox response.write "<input type=checkbox...
10
5230
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named 'CheckAllRows' on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the...
4
7507
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to checkchekboxes and click the Delete button. That will show a confirmation dialog message with the items they choose to delete.
0
4110
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me with my problems. Now for my new little problem,I had a problem posting the values from checkbox fields to a database and thats the obstacle I overcame. Now the second part is my new problem is that I want that the next time that page loads for...
0
9993
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
9839
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
11256
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...
1
10946
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
9658
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
8034
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
7187
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
6076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4705
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.