473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

checkbox function returning same result for on and off

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>Customer Inquiry</title>
<SCRIPT language="JavaScript1.2">
function txtReasonState(name)
{
if (document.sysaccess.name.checked==false)
{
alert("uncheked");
}
else
{
alert("checked");
}

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

<form name="sysaccess" >
<input type="checkbox" name="checkbox1" onClick="txtReasonState(this.name)">

</form>

</body>
</html>

thax
Manoj
Jun 11 '07 #1
10 1708
dmjpro
2,476 2GB
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>Customer Inquiry</title>
<SCRIPT language="JavaScript1.2">
function txtReasonState(name)
{
if (document.sysaccess.name.checked==false)
{
alert("uncheked");
}
else
{
alert("checked");
}

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

<form name="sysaccess" >
<input type="checkbox" name="checkbox1" onClick="txtReasonState(this.name)">

</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 Expert Mod 4TB
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
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 2GB
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('element_name').attr is possible but using form_obj it is something wrong.
Right?

Kind regards,
Dmjpro.
Jun 11 '07 #5
gits
5,390 Expert Mod 4TB
Oh .... that's why i thought how is it possible?
Actually in IE document.all('element_name').attr 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 Expert Mod 4TB
... but i testet it now in IE ... and:

[HTML]
<html>
<head>
<title>Customer Inquiry</title>
<SCRIPT language="JavaScript1.2">
function txtReasonState(name) {
if (document.sysaccess[name].checked == true) {
alert("checked");
} else {
alert("unchecked");
}
}
</SCRIPT>

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

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

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

[HTML]
<html>
<head>
<title>Customer Inquiry</title>
<SCRIPT language="JavaScript1.2">
function txtReasonState(name) {
if (document.sysaccess[name].checked == true) {
alert("checked");
} else {
alert("unchecked");
}
}
</SCRIPT>

</head>
<body>
<form name="sysaccess" >
<input type="checkbox" name="checkbox1" onClick="txtReasonState(this.name)">
</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 Expert Mod 4TB
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
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
gits
5,390 Expert Mod 4TB
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
yep ... i suspected this ;) ... the first one passes a reference to the obj itself to the function ... the second one passes only the name to it ... so, if you want to use the first you now should know what you had to change within our function, assuming you want to refer with the shown method? (note: you don't need to refer a document-node in that case ... obj is the correct node already, and you may ask for its properties directly = dmjpro's solution)

[HTML]
<html>
<head>
<title>Customer Inquiry</title>
<SCRIPT language="JavaScript1.2">

function txtReasonState(obj) {
if (document.sysaccess[obj.name].checked == true) {
alert("checked");
} else {
alert("unchecked");
}
}

</SCRIPT>

</head>
<body>
<form name="sysaccess" >
<input type="checkbox" name="checkbox1" onClick="txtReasonState(this)">
</form>
</body>
</html>[/HTML]

kind regards ....
Jun 11 '07 #11

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

Similar topics

2
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)" ........
3
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...
6
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...
2
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...
7
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...
4
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...
1
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...
0
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...
26
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.