473,804 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checkbox function returning same result for on and off

11 New Member
hi,

This is my program and it is resluting same message "checked" everytime, either i checed it or unchecked the given checkbox.

Please have a look .

<html>
<head>
<title>Custom er Inquiry</title>
<SCRIPT language="JavaS cript1.2">
function txtReasonState( name)
{
if (document.sysac cess.name.check ed==false)
{
alert("uncheked ");
}
else
{
alert("checked" );
}

}
</SCRIPT>
</head>
<body>

<form name="sysaccess " >
<input type="checkbox" name="checkbox1 " onClick="txtRea sonState(this.n ame)">

</form>

</body>
</html>

thax
Manoj
Jun 11 '07 #1
10 1738
dmjpro
2,476 Top Contributor
hi,

This is my program and it is resluting same message "checked" everytime, either i checed it or unchecked the given checkbox.

Please have a look .

<html>
<head>
<title>Custom er Inquiry</title>
<SCRIPT language="JavaS cript1.2">
function txtReasonState( name)
{
if (document.sysac cess.name.check ed==false)
{
alert("uncheked ");
}
else
{
alert("checked" );
}

}
</SCRIPT>
</head>
<body>

<form name="sysaccess " >
<input type="checkbox" name="checkbox1 " onClick="txtRea sonState(this.n ame)">

</form>

</body>
</html>

thax
Manoj

Change at two places.

Expand|Select|Wrap|Line Numbers
  1. <!--<input type="checkbox" name="checkbox1" onClick="txtReasonState(this.name)">-->
  2. <input type="checkbox" name="checkbox1" onClick="txtReasonState(this)">
  3.  
Expand|Select|Wrap|Line Numbers
  1. //if (document.sysaccess.name.checked==false)
  2. if (name.checked==false)
  3.  
Explaination:
U r passing the parameter as string but u can't do directly like this as u did in if expression.
Right?

Best of luck.

Kind regards,
Dmjpro.
Jun 11 '07 #2
gits
5,390 Recognized Expert Moderator Expert
hi ...

yep ... that would be one solution. An other would be to change the expression for the condition to:

Expand|Select|Wrap|Line Numbers
  1. if (document.sysaccess[name].checked == false) {
  2.     // your code follows here
  3. }
  4.  
with refering the above way (with .name) we refer to properties and methods of an object, and we would refer a property named 'name' ... that we don't have. to use a variable property-name we may use the usual array-reference-syntax shown above ... so we would use the object as a assoc array ...

kind regards ...
Jun 11 '07 #3
manojsingh
11 New Member
hi,

thanx dmjpro it is working fine, but gits also tried your solution and it is not working.

thanx again both of you for reply
Jun 11 '07 #4
dmjpro
2,476 Top Contributor
hi ...

yep ... that would be one solution. An other would be to change the expression for the condition to:

Expand|Select|Wrap|Line Numbers
  1. if (document.sysaccess[name].checked == false) {
  2.     // your code follows here
  3. }
  4.  
with refering the above way (with .name) we refer to properties and methods of an object, and we would refer a property named 'name' ... that we don't have. to use a variable property-name we may use the usual array-reference-syntax shown above ... so we would use the object as a assoc array ...

kind regards ...

Oh .... that's why i thought how is it possible?
Actually in IE document.all('e lement_name').a ttr is possible but using form_obj it is something wrong.
Right?

Kind regards,
Dmjpro.
Jun 11 '07 #5
gits
5,390 Recognized Expert Moderator Expert
Oh .... that's why i thought how is it possible?
Actually in IE document.all('e lement_name').a ttr is possible but using form_obj it is something wrong.
Right?

Kind regards,
Dmjpro.

hi ... it seems to work in gecko-browsers (FF, Moz, ...) ... sorry for not testing it in IE ... so you should use dmjpros solution. i nearly never use this kind of refering to document elements because i personaly find it much better to use dom-methods ... and i didn't know about the IE-issue with my solution ...

kind regards ...
Jun 11 '07 #6
gits
5,390 Recognized Expert Moderator Expert
... but i testet it now in IE ... and:

[HTML]
<html>
<head>
<title>Custom er Inquiry</title>
<SCRIPT language="JavaS cript1.2">
function txtReasonState( name) {
if (document.sysac cess[name].checked == true) {
alert("checked" );
} else {
alert("unchecke d");
}
}
</SCRIPT>

</head>
<body>
<form name="sysaccess " >
<input type="checkbox" name="checkbox1 " onClick="txtRea sonState(this.n ame)">
</form>
</body>
</html>
[/HTML]

it works ... can you tell me where you get an error?

kind regards ...
Jun 11 '07 #7
dmjpro
2,476 Top Contributor
... but i testet it now in IE ... and:

[HTML]
<html>
<head>
<title>Custom er Inquiry</title>
<SCRIPT language="JavaS cript1.2">
function txtReasonState( name) {
if (document.sysac cess[name].checked == true) {
alert("checked" );
} else {
alert("unchecke d");
}
}
</SCRIPT>

</head>
<body>
<form name="sysaccess " >
<input type="checkbox" name="checkbox1 " onClick="txtRea sonState(this.n ame)">
</form>
</body>
</html>
[/HTML]

it works ... can you tell me where you get an error?

kind regards ...

Sorry without having knowledge i commented wrong.
Is it possible and compatible with all browsers.
Sorrryyy.

Kind regards,
Dmjpro.
Jun 11 '07 #8
gits
5,390 Recognized Expert Moderator Expert
Sorry without having knowledge i commented wrong.
Is it possible and compatible with all browsers.
Sorrryyy.

Kind regards,
Dmjpro.
... hmmm ... in my opinion it should work with all browsers (now tested it in IE, FF, MOZ - may try safari at home this evening and opera too), because you refer a collection of elements contained by a form. refering an form-element by its name may be done through the 2 shown ways here ... but i'm not really sure about IE-issues until i don't use it (and i was a little bit confused about it and tested it) ... and like i said ... i prefer the dom-way for all things to do with elements ...

and i think it works with all collections like:

Expand|Select|Wrap|Line Numbers
  1. var name = 'foo';
  2.  
  3. // refering an element with name foo
  4. document.all[name].property
  5.  
  6. // when element with name foo is contained by an form-element
  7. // note formname must be the name of the form
  8. document.formname[name].property
  9.  
  10. // and of course you should be able to do:
  11. // formname is now variable and is 'bar'
  12. var formname = 'bar';
  13.  
  14. document[formname][name].property
kind regards ...
Jun 11 '07 #9
manojsingh
11 New Member
hi gits,

it is now working, What i did was changed the parameter in
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <input type="checkbox" name="checkbox3" onClick="txtReasonState(this)">
  4.  
  5.  
  6. but it works
  7. <input type="checkbox" name="checkbox3" onClick="txtReasonState(this.name)">
  8.  
  9.  
thanx
manoj
Jun 11 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1899
by: Fred | last post by:
Hi, I defined a form consisting of checkboxes like: <form> <input type="checkbox" name=ck id=ck onclick="check(this.form)" <input type="checkbox" name=ck id=ck onclick="check(this.form)" ..... <input type="checkbox" name=ck id=ck onclick="check(this.form)" </form>
3
2309
by: Dennis Chang | last post by:
Hi all, I was reading about function pointers and came across something which intrigued me. K&R2 calls qsort (pg.119) within main as so: qsort( (void **) lineptr, 0, nlines-1, (int (*) (void *, void*))(numeric ? numcmp : strcmp) ); I guess what interests me is the nameless function pointer and then the
6
2432
by: Generic Usenet Account | last post by:
Is it okay to return a local datastructure (something of type struct) from a function, as long as it does not have any pointer fields? I think it is a bad idea, but one of my colleagues does not seem to think so. According to my colleague, if the data structure does not "deep copy" issues, it is perfectly okay to return a local variable. This is because at the point of invocation, a copy of the data structure is made. In all fairness...
2
2064
by: Marty | last post by:
I have a numeric Oracle field which stores -1 for true and 0 for false. I am trying to populate a checkbox in a datagrid. In my SQL statement, I used the Decode function so that when it populates the dataset that I would store the string 'true' and 'false' rather than a numeric value. I did this because I thought it would make it easier to actually set the value in the checkbox. Anyway, I bind the dataset to the datagrid. In my HTML...
7
5550
by: Ryan Ternier | last post by:
I have a check box on my page. When a user clicks this box I have a confirmation box come up. When the user clicks OK, true is returned, otherwise false. Now, when true is Returened, I want the form to postback. I can't figure out how to do this. Here is the code I use to put the OnClick event on the CHeckbox.
4
7505
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.
1
1980
by: empiresolutions | last post by:
im using the script.aculo.us drag n drop script. i am having an issue getting a checkbox to POST its value if checked, once the row the checkbox is in is moved. I believe that once i change the position of a checkbox, it is no longer considered a child of the parent form. How can i get it back to being part of the original parent form? Another way of saying is... If i have 10 rows with checkbox's in each row, i check rows 1,2,3,4, then move...
0
4105
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...
26
4888
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure about the syntax of calling the same. #include <stdio.h> void fp1()
0
9714
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
9594
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
10600
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
10096
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
9174
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
5534
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
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
2
3834
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.