• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help to disable a check box.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I want to disable a check box whenever I select "deny" in the dropdown list.My code is

function go(name)
{
var mylist=document.getElementById(name)

var chbox = document.getElementById("chxbox")

if(mylist.options[mylist.selectedIndex].text == "deny")
{

if(chbox.checked==true)
chbox.checked=false
chbox.disabled=true
alert("selected")
}
else
{
alert("else chbox")
chbox.disabled=false
}

}
</script>
</head>

<body>
<form>
Deactivate <input type="checkbox" name="a_6646_chx" id="chxbox" value="">
Action
<select id="order-process" name="order-process" onchange="go(this.name)" size="1">
<option value="none"></option>
<option value="">approve</option>
<option value="">deny</option>
</select><br><br>

Deactivate <input type="checkbox" name="a_6645_chx" id="chxbox" value=" ">
Action
<select id="order-process" name="order-process" onchange="go(this.name)" size="1">
<option value="none"></option>
<option value=" ">approve</option>
<option value=" ">deny</option>
</select><br><br>

Deactivate <input type="checkbox" name="a_6648_chx" id="chxbox" value=" ">
Action
<select id="order-process" name="order-process" onchange="go(this.name)" size="1">
<option value="none"></option>
<option value=" ">approve</option>
<option value=" ">deny</option>
</select><br><br>

Deactivate <input type="checkbox" name="a_6649_chx" id="chxbox" value=" ">
Action
<select id="order-process" name="order-process" onchange="go(this.name)" size="1">
<option value="none"></option>
<option value=" ">approve</option>
<option value=" ">deny</option>
</select>
</form>

</body>
</html>


It works only for the fist option I want that to work for all rows/check boxes seperately.

Please suggest how can I fix this

Thanks
Bharathi
 
Sheriff
Posts: 67746
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
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and most people will just go elsewhere. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Bear Bibeault
Sheriff
Posts: 67746
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 can't have more than one element with the same id.
 
Bharathi vallab
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Thanks Bear Bibeault for Your reply.
Is there a way to pass "id" of check box as parameter to onchange() of dropdown list
like

or is there any other way to make this work.
 
Bear Bibeault
Sheriff
Posts: 67746
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
Have you tried it? Why wait for an answer to a question here when it would take you less than a minute to try it yourself?
 
Bharathi vallab
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it before I could post here.checkbox id in the method onchange is passing null
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An id is a string, try:
onchange="go(this.name,'chxbox2')"

Note the quotes around 'chxbox2'.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also note:

the id and the name of an element has to be the same for IE to work correctly.

Eric
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic