473,574 Members | 2,533 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 6435
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
4641
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
2120
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...
5
9155
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
3662
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...
2
14624
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
3772
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...
10
5193
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...
4
7491
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
4087
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...
0
7794
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...
0
7710
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...
0
8225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5610
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...
0
5296
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...
0
3738
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...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2230
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
1
1332
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.