strategos Posted January 16, 2012 Share Posted January 16, 2012 Hello, I am trying to create a form that checks for errors and changes the class of an HTML <li> so it can highlight the error. I need to be able to compare PHP vars on a different page and change the class of the HTML <li> if it is an error. <li id="foli111" class="notranslate"> <label class="desc" id="title111" for="Field111"> Please enter your SteamID here or choose "Anonymous" </label> <div> <input id="steamid" name="Field111" type="text" class="field text medium" value="" maxlength="30" tabindex="3" onkeyup="" /> </div> </li> I want the class to change from "notranslate" to "notranslate error" Another example is this http://wufoo.com/gallery/templates/online-orders/donation-form/ (the template im using) Link to comment https://forums.phpfreaks.com/topic/255171-get-php-to-change-html-classes/ Share on other sites More sharing options...
gizmola Posted January 16, 2012 Share Posted January 16, 2012 That's great. Where is your code? Link to comment https://forums.phpfreaks.com/topic/255171-get-php-to-change-html-classes/#findComment-1308368 Share on other sites More sharing options...
strategos Posted January 17, 2012 Author Share Posted January 17, 2012 Im wondering what function I could use to do it, therefore I have no PHP code already Link to comment https://forums.phpfreaks.com/topic/255171-get-php-to-change-html-classes/#findComment-1308431 Share on other sites More sharing options...
Proletarian Posted January 17, 2012 Share Posted January 17, 2012 Obviously, the class parameter is going to need a variable as its value. Your function would determine via a conditional statement whether this variable is "notranslate" or "notranslate error". Then however you execute the code you should get the results you want. PSUEDO CODE EXAMPLE function whatever(x) { if (x == true) { var = "notranslate"; } else { var = "notranslate error"; } return var; } class = whatever(x); // rest of code You find the x variable based on whatever check you are doing to determine what the styling should be. I hope this helps get you going in the right direction. Link to comment https://forums.phpfreaks.com/topic/255171-get-php-to-change-html-classes/#findComment-1308713 Share on other sites More sharing options...
strategos Posted January 21, 2012 Author Share Posted January 21, 2012 I figured it out. You have to echo php inside of the class. Thanks! Link to comment https://forums.phpfreaks.com/topic/255171-get-php-to-change-html-classes/#findComment-1309852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.