File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Radio button" Watch "Radio button" New topic
Author

Radio button

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
FORM action="TestList.do" method="post" name="form"

INPUT type="radio" name="qtryear" value="Qtr"
onclk ="form.chkbox1.disabled=false";

Quarter

INPUT type="checkbox" name="chkbox1" value="1-1-2001"
1st Quarter
INPUT type="checkbox" name="chkbox1" value="1-1-2002"
2nd Quarter
INPUT type="checkbox" name="chkbox1" value="1-1-2003"
3rd Quarter
INPUT type="checkbox" name="chkbox1" value="1-1-2004"
4th Quarter
BR

INPUT type="radio" name="qtryear" value="Year"
onClk="form.chkbox1.disabled=true" ;
/
Year
br
input type = submit name = submit value = submit /

/FORM


I would like to disable checkbox if type2 radio is clicked and enable check box when type1 radio is clicked.
Above code does not work why?

onClick as onclk
</FORM>
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
because you have 4 elements named the same thing so it will not work
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I want to write a function that will be called when I click on the radio.

If i click on type 1 I want to enable check box and on type 2 disable chk box.

How do I pass all the check boxes to the function at the same time

this is working ..but I would like to call a function and pass the check boxes ...

onClck=
form.chkbox1.disabled=true
form.chkbox2.disabled=true
form.chkbox3.disabled=true
form.chkbox4.disabled=true
[ September 24, 2004: Message edited by: shan javan ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
@#111;nclick="document.formName.chkbox1.disabled=true;document.formName.chkbox2.disabled=true;document.formName.chkbox3.disabled=true;document.formName.chkbox4.disabled=true"


You can use the same name, but they would be an array format
chkbox1[0]
chkbox1[1]
chkbox1[2]
chkbox1[3]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
FORM action="TestList.do" method="post" name = form
INPUT type="radio" name="qtryear" value="type1"
onClck="disen(form.chkbox,true)";

INPUT type="radio" name="qtryear" value="tyep2"
onClck="disen(form.chkbox,false)";

function disen (chBox,bool){
for (i=0;i<chBox.length;i++){
chBox[i].disable = bool
}
}
This code says object expected ? What is the mistake?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have your javascript stored in as abc.js

In my html I include
<script language="JavaScript" src="abc.js">
</script>

How do I pass the objects to my abc.js ?
where I have the your script

For eg document.Form1 .... works fine if both code and js are in same page.
enable(this,true,'cb')

I need to pass the this object to abc.js which is a different file.
[ September 29, 2004: Message edited by: shan javan ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You should not have to do anything different by including the code as an external JavaScript file.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
it says object expected!! why?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Well that error means:

1- the page has not loaded completely and it is looking for the element on the page, you did not link to the js file correctly, or you included script tags inside of the js file.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Radio button
 
Similar Threads
Please help me regarding the forms selection
Passing check box value to servlet.
html radio button add to database
help with radio buttons
Display data from database to jsp page.