• 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

javascript error

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

I have a code to in javascript which will be executed when the checkbox is checked or unchecked

the issue it is working fine in my browser mozilla(6.0.2) and IE 8 and is not working fine for the other person dnt know exactly what browser he is using so can you suggest me a solution. the code is as below

<input type="checkbox" name="display" value="on" onclick="javascript: return doption()" >

function doption()()
{
var form = document.forms[0];
if (form.display.checked == true){
document.getElementById("h1").color = "#4D4D4D";
document.getElementById("h2").color = "#4D4D4D";
document.getElementById("h3").color = "#4D4D4D";
document.getElementById("h4").color = "#4D4D4D";
}
else{

document.getElementById("h1").color = "#E5E5E5";
document.getElementById("h2").color = "#E5E5E5";
document.getElementById("h3").color = "#E5E5E5";
document.getElementById("h4").color = "#E5E5E5";
}
}

the error is form.display is null or not identified but I am not getting any error in any of my browser
 
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
In both of these lines of code:
you should be using document.getElementById() to address elements rather than the old fashioned ways that you are using.
 
ramu somu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:In both of these lines of code:
you should be using document.getElementById() to address elements rather than the old fashioned ways that you are using.




Thank you Eric

I have one more doubt it was working fine 2 days back why am I getting error now
 
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
Well Eric is helpful and cool, but I'm Bear.

I can't tell you why it was and now isn't working, I just know that the old way of addressing is fragile can cause problems when seemingly unrelated changes are made elsewhere on the page.

Assigning a unique id to an element and using document.getElementById() always works exactly as expected.
 
ramu somu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Well Eric is helpful and cool, but I'm Bear.

I can't tell you why it was and now isn't working, I just know that the old way of addressing is fragile can cause problems when seemingly unrelated changes are made elsewhere on the page.

Assigning a unique id to an element and using document.getElementById() always works exactly as expected.



I am so sorry bear I was talking with my team mate eric and by mistake specified it as eric

Thanks a lo bear fr your help
 
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
No problem.

Post back with your results. If after changing to using id values the problem persists, there must be something else at play.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic