Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

changing a certain text with if else statement

Featured Replies

Hello,

 

I have developed a form and if the user does not submit something an error occurs.

 

I was wondering how to change the text color

 

 

<li id="first_name">
<label for="first_name">First name: </label>
<div class="fieldgroup">
<?php echo $form->error("first_name"); 
echo "<br>";
?>
<input name="first_name" type="text" value="<?php echo $form->value("first_name"); ?>" size="35" maxlength="30"></div></li>

 

Right now this is how my code looks. It produces an error when its necessary. But I want to instead of producing that error, I want the First name text to change colors

 

 

I might have to a if else statement? But not sure how it looks

 

Thanks

I have developed a form and if the user does not submit something an error occurs.

 

Data validation for form submission is usually done using JavaScript, which is not server side. To change the color of the text of an element, you can add 'OnClick=changeColour()' to the submit button and then create the function changeColour() which changes the styling associated with 'first_name' by using getElementById.

  • Author

webdesigner93 showed me a way last night on aim. he was really helpful. He got it to work, by changing the color on submit, but I forgot to check another part to it. When I type something in the form, the error disappears. So when I tried to change the original text color, it disappears when the user correctly inputs the right data.

 

 

How do I make it so it'll go back,

 

Here's his snippet of code that he helped me out with.

 

 

<?php 
if($error_tri === FALSE) { 
echo "Username: "; 
}
else if($error_tri === TRUE) { 
echo $form->error("user"); 
} 
?>

webdesigner93 showed me a way last night on aim. he was really helpful. He got it to work, by changing the color on submit, but I forgot to check another part to it. When I type something in the form, the error disappears. So when I tried to change the original text color, it disappears when the user correctly inputs the right data.

 

 

How do I make it so it'll go back,

 

Here's his snippet of code that he helped me out with.

 

 

<?php 
if($error_tri === FALSE) { 
echo "Username: "; 
}
else if($error_tri === TRUE) { 
echo $form->error("user"); 
} 
?>

 

Mmm no the below was my code i think u must have changed it

 


<?php if($error_tri === FALSE) { 
echo "<span style='color:#000000;'>";
}
else if($error_tri === TRUE) 
{ 
echo "<span style='color:#FF0000;'>"; 
} ?>
Username: 
<?php echo "</span>"; ?>

  • Author

Yeah, sorry. I did change it a little. I changed it a little so when the user does not enter something, the error pops up. But when the user does enter something, I want the color to change back to the original color text (black). How do I make it convert back to error_tri === False after the error has been set. Currently, it stays red.

 

Thank you :)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.