I have a situation where I need the ID of a div tag to change according to the name of the last button a user clicked. I use this code: <div id="<?php echo $last_selected;?>" class="align_left"> Code (markup): This works fine and seems to function in all browsers and so forth but W3C validator doesn't seem to agree and gives me a : syntax of attribute value does not conform to declared value <div id=" " class="align_left"> ✉ The value of an attribute contained something that is not allowed by the specified syntax for that type of attribute. For instance, the “selected†attribute must be either minimized as “selected†or spelled out in full as “selected="selected"â€; the variant “selected=""†is not allowed. I was wondering if there's a better way to do this? Haven't been able to find an answer anywhere and was hoping someone can make a suggestion. Thanks
Try this: <?php if(isset($last_selected) && !empty($last_selected)) { ?> <div id="<?php echo $last_selected;?>" class="align_left"> <?php } else { ?> <div class="align_left"> <?php } ?> PHP: There is lots of room for improvement of this code, but I have show you that what you can do to remove the error you are getting. Best of luck..
Based on @xpertdev if there's no value for $last_selected it will echo id="1", of course replace 1 with a desired value <div id="<?php if(empty($last_selected)){echo $last_selected="1";}else{echo $last_selected;}?>" class="align_left"> PHP:
@MyVodaFone : Yes I have already mentioned that there are lots of room for improvement. I was just pointing him in right direction....
Thanks for all the info, the code example doesn't suit my purpose but just at a glance it made me realize that indeed the original value is empty! DOH!! Sometimes you just need a 2nd pair of eyes to see the obvious. Thank you for the input. I decided to reassess my approach and changed all my unique IDs to class, and set a default class to each one, solved my problem and even shrunk my css file a bit. Again thank you for the help.