0

I want that onload the <span> and <checkbox> classes to be blank:

<span id="checkboxx_<?php  echo $nrs['id'];   ?>" class="highlight" > 
   <input type="checkbox" class="checkboxx" id="checkboxx_<?php  echo $nrs['id'];   ?>" style="padding: 0px; margin: 2px;"   <?php echo $value == 1 ? 'checked="checked"' : ''?>>                       
</span>

i have tried this

<?php
if($value==1)
{
?>
  <script>
    if (this.checked) {
      document.getElementById("checkboxx_<?php  echo $nrs['id'];   ?>").className = "";
    }
  </script>
<?php
} else {
?>
   <script>$j("#"+pos).addClass("highlight");</script>
<?php
}

but this doesn't work.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
user930026
  • 1,647
  • 5
  • 34
  • 59
  • Check this link, there is solution: http://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript – Elvin Haci Sep 22 '11 at 09:25
  • No offense, but how did you expect this code ever to work? Did you read any tutorial about PHP and JavaScript? It seems you just copy and pasted stuff together... I suggest you to take some time and learn the basics about JavaScript (and maybe PHP). The [MDN JavaScript Guide](https://developer.mozilla.org/en/JavaScript/Guide) is a good start. – Felix Kling Sep 22 '11 at 09:47

2 Answers2

2
document.getElementById("MyElement").className =
document.getElementById("MyElement").className.replace(/(?:^|\s)MyClass(?!\S)/ , '')
Shefali Aggarwal
  • 728
  • 4
  • 12
0

actually you have duplicate IDs in your code checkboxx_<?php echo $nrs['id']; ?> for span and checkbox, and also this code is buggy and wont work

<script>if (this.checked) {
            document.getElementById("checkboxx_<?php  echo $nrs['id'];   ?>").className = "";
            }
        </script>

i think it will a be better way to use smth like this:

<span class="<?php echo ($value !== 1 ? 'highlight' : '') ?>" > 
   <input type="checkbox" class="checkboxx" style="padding: 0px; margin: 2px;"   <?php echo $value == 1 ? 'checked="checked"' : ''?>>                       
</span>
Dmitry
  • 812
  • 8
  • 13
  • span and checkbox id is made same intentionally. and javascrpt code shown above is like have shown that tried both methods – user930026 Sep 22 '11 at 10:58