• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Enabling and disabling Check Boxes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script language="javascript">
function chMd()
{
// initialize form with empty field
document.forms[0].text1.disabled=false;
document.forms[0].text1.value="";

document.forms[0].text2.disabled=false;
document.forms[0].text2.value="";

document.forms[0].text3.disabled=false;
document.forms[0].text3.value="";

document.forms[0].goServer.disabled=false;
for(var i=0;i<document.forms[0].elements.length;i++)
{
if(document.forms[0].elements[i].name=="checkbox")
{
if(document.forms[0].elements[i].value=="c1")
{
if(document.forms[0].elements[i].checked==true){

document.forms[0].text1.disabled=false;
document.forms[0].text2.disabled=true;
document.forms[0].text3.disabled=true;



document.forms[0].goServer.disabled=true;
}
if(document.forms[0].elements[i].value=="c2")
if(document.forms[0].elements[i].checked==true)
{
document.forms[0].text2.disabled=false;
}

if(document.forms[0].elements[i].value=="c3")
if(document.forms[0].elements[i].checked==true)
{
document.forms[0].text3.disabled=false;
}
}

else if(document.forms[0].elements[i].value=="c2")
{
if(document.forms[0].elements[i].checked==true){
document.forms[0].test2.disabled=false;
document.forms[0].Text1.disabled=true;
document.forms[0].Text3.disabled=true;
document.forms[0].goServer.disabled=false;
}
if(document.forms[0].elements[i].value=="c1")
if(document.forms[0].elements[i].checked==true)
{
document.forms[0].text1.disabled=false;
}

if(document.forms[0].elements[i].value=="c3")
if(document.forms[0].elements[i].checked==true)
{
document.forms[0].text3.disabled=false;
}
}
else if(document.forms[0].elements[i].value=="c3")
{
if(document.forms[0].elements[i].checked==true){
document.forms[0].text3.disabled=false;
document.forms[0].Text2.disabled=true;
document.forms[0].Text1.disabled=true;

document.forms[0].goServer.disabled=false;
}
if(document.forms[0].elements[i].value=="c1")
if(document.forms[0].elements[i].checked==true)
{
document.forms[0].text1.disabled=false;
}

if(document.forms[0].elements[i].value=="c2")
if(document.forms[0].elements[i].checked==true)
{
document.forms[0].text2.disabled=false;
}
}
}
}
}




></script>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox" value="c1" onClick="chMd()"/>
Firstname</label>
<label>
<input type="text" name="text1" disabled="disabled"/>
</label>


<label>
<input type="checkbox" name="checkbox" value="c2" onClick="chMd()"/>
Lastname</label>
<label>
<input type="text" name="text2" disabled="disabled"/>
</label>



<label>
<input type="checkbox" name="checkbox" value="c3" onClick="chMd()" />
Address</label>
<label>
<input type="text" name="text3" disabled="disabled" />
</label>



<label>
<input type="submit" name="Submit" value="Submit" />
</label>


</form>
</body>
</html>


I have provided my code. What i want to do is, i want to disable all other check boxes along with text boxes, when i go for check box 1, when i check the check box2, check box along with text box 1 and 2 both will be enabled. and similarly for check box 3.Can anybody please help me. Thank You in advance.
 
Sheriff
Posts: 67693
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Firstly, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

Secondly, this is something that you'd do with JavaScript, not JSP. As such, this topic has been moved to the JavaScript forum.
 
Bear Bibeault
Sheriff
Posts: 67693
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You provided a lot of code, but did not indicate what problems you are having with it. What aspect are you having trouble with?

And... document.forms[0] is an antiqauted and fragile way to address ewlements. Time to modernize your code a bit and use id values and document.getElementById().
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds all to similar to this. From brand new members, no less. Homework?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic