Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Cannot Access Checkbox
darran
post Feb 26 2007, 12:55 AM
Post #1


Privileged Member
*********

Group: Members
Posts: 661
Joined: 31-August 06
From: Singapore
Member No.: 29,189



I did a form, I created a checkbox under the same name 'lead_role' but I can't seem to access it in my javascript validation.

This is the code in my HTML page
CODE
<input name="lead_role" id="lead_role" type="checkbox" class="style30" value="1">


And this is the validation I am testing out
CODE
alert(document.form1.lead_role.checked);


My browser returns me an 'undefined' alert message.

The only way I was successful in accessing the element is using the getElementById() method but that only gets the very first instance of the checkbox.

Can anyone help me out? Thanks

This post has been edited by darran: Feb 26 2007, 12:55 AM
Go to the top of the page
 
+Quote Post
electriic ink
post Feb 26 2007, 08:20 AM
Post #2


Incest is a game the whole family can play.
Group Icon

Group: [MODERATOR]
Posts: 1,216
Joined: 11-February 05
From: Heaven
Member No.: 3,709



I made this code and tested it out in my browser, Firefox:

HTML
<head></head>
<body> <form name="form1"> <input name="lead_role" type="checkbox" class="style30" checked> </form>

<script> if (document.form1.lead_role.checked==1) { alert(document.form1.lead_role.checked); } </script></body>


I had to replace value="1" with checked because the latter worked at checking the box but the former didn't.

My guesses would be:
  • You tried to refer to an object that hadn't been already set (put the javascript after the html).
  • You didn't put the <form name="form1"> bit in your code, so when it looked for an object whose name was form1 it couldn't find it.
Anyway, if that doesn't solve the problem, it helps if you post the entire page of code that you are using.
Go to the top of the page
 
+Quote Post
darran
post Feb 26 2007, 10:35 AM
Post #3


Privileged Member
*********

Group: Members
Posts: 661
Joined: 31-August 06
From: Singapore
Member No.: 29,189



I don't think it is a problem you are saying. This is where my javascript is located.

CODE
<head>&lt;script language="javascript" type="text/javascript" src="validation.js"></script></head>


This is how my form was created.

CODE
<form name="form1" id="form1" onsubmit="return validate();" action="register_process.asp">


Please reply me ASAP as I am rushing for time.

I have attached the form as well as the javascript, hope to get a reply soon.
Attached File(s)
Attached File  form.txt ( 75.83k ) Number of downloads: 2
Attached File  js.txt ( 11.16k ) Number of downloads: 2
 
Go to the top of the page
 
+Quote Post
saga
post Feb 27 2007, 04:39 PM
Post #4


Premium Member
********

Group: Members
Posts: 165
Joined: 12-September 05
Member No.: 11,777



You can not use or it will return an error if you try to use a form element or any object that belongs to the body section of an html until it is instantiated unless you load the code on the opening <body> tag using the onload="" event.

So if you want to set the value of the checkbox do so by using the event onload="" in the <body> tag.

By the way the attribute name="" is not supported by XHTML 1.0
Go to the top of the page
 
+Quote Post
darran
post Feb 28 2007, 01:47 AM
Post #5


Privileged Member
*********

Group: Members
Posts: 661
Joined: 31-August 06
From: Singapore
Member No.: 29,189



I have found a solution to the problem, but I don't know if it was actually the solution.

I used the same name for every checkbox meaning 5 checkbox being named as lead_role or something. I name it as different seperate names, and it works perfectly fine. Thanks for all your help anyways smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Access and VBA Manual...(1)
  2. Dreamweaver Permissions Issue(5)
  3. Which Proxy Sites Can Be Used To Access The Websites?(28)
  4. Hotspot Virtual Machine Exception_access_violation(4)
  5. Is It Possible To Access The Mysql Remotely?(10)
  6. I Cannot Access My Site. [resolved](13)
  7. Problems With Ftp Access(1)
  8. Irc On Your Java Enabled Mobile!(1)
  9. Free Domain With Dns Record Access(1)
  10. Unable To Access Cpanel(6)
  11. Cannot Access Cpanel...(3)
  12. Mouse Input In C Programs(5)
  13. Acessing Files In Mac Os X(0)
  14. Sub Domain Problem : Urgent(10)
  15. Ms-access Database Question(3)
  1. Server Issues? Web Site Down? Cpanel Access?(48)
  2. Can't Access Cpanel(10)
  3. Anonymous Ftp Access?(2)
  4. Ftp Access Has Stopped Working All Of A Sudden [resolved](5)
  5. Remote Access Mysql(8)
  6. I Cant Access The Server!(1)
  7. Official: Can't Access My Cpanel - Supports From Admins(69)
  8. How Do I Find My Mysql Password? [resolved](5)
  9. Almost There, However.... [resolved](7)
  10. Can't Access My Site....weird Issue(5)
  11. Can't Access My Site An Cpanel(4)
  12. No Site Access(4)
  13. Hosting Problem [resolved](22)


 



- Lo-Fi Version Time is now: 30th August 2008 - 01:57 AM