Jump to content

Get PHP to change HTML classes


strategos

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.