0

This is my HTML span and Input line where I set it to display:none (hardcoded).

I want this to be show if accountstatus is equal to animaldead

Here's my HTML input and span

        <span class = 'v10' style="display:none;"><span style='color:#FF0000;'>*</span>Inception Date:<br /></span>
    <input name='period_from'  class = 'v11' value = "<?php echo $incepd; ?>" onblur="validateg('<?php echo $fieldstovalidate; ?>','<?php echo $submitbtns; ?>');" id = 'period_from'   onfocus=showCalendar('',this,this,'".$period_from."','period_fromd',0,23,1); onfocus=returbcolorback('period_from'); style = 'height:21px;width:140px;display:none' type='text'  />

Now here's my if statement

if(strtolower($accountstatus) == 'animaldead')
{ $trutype = "selected";
  how will I show it here......
}

3 Answers 3

1
$style = 'none';
if(strtolower($accountstatus) == 'animaldead'){ 
   $trutype = "selected";
   $style = 'block';
}

and change span is like that

<span class = 'v10' style="display:<?php echo $style; ?>;">

using this way you don't need to copy the same code twice.

Sign up to request clarification or add additional context in comments.

Comments

0
$block = "block";
  $none = "none";
if(strtolower($accountstatus) == 'animaldead')
{ $trutype = "selected";

?>     <span class = 'v10' style="display:<?php echo $block; ?>; "><span style='color:#FF0000;'>*</span>Inception Date:<br /></span>
    <input name='period_from'  class = 'v11' value = "<?php echo $incepd; ?>" onblur="validateg('<?php echo $fieldstovalidate; ?>','<?php echo $submitbtns; ?>');" id = 'period_from'   onfocus=showCalendar('',this,this,'".$period_from."','period_fromd',0,23,1); onfocus=returbcolorback('period_from'); style = 'height:21px;width:140px;display:none' type='text'  />
}
else{
<span class = 'v10' style="display:<?php echo $none; ?>; "><span style='color:#FF0000;'>*</span>Inception Date:<br /></span>
    <input name='period_from'  class = 'v11' value = "<?php echo $incepd; ?>" onblur="validateg('<?php echo $fieldstovalidate; ?>','<?php echo $submitbtns; ?>');" id = 'period_from'   onfocus=showCalendar('',this,this,'".$period_from."','period_fromd',0,23,1); onfocus=returbcolorback('period_from'); style = 'height:21px;width:140px;display:none' type='text'  />


}

You create 2 variables one for display block and one for display none. Now php and html can be written together so if it is == animaldead you put display:block as shown in the code above. Else you put display none... Cheers :D

Comments

0

A more elegent way than hardcoding the property inside the html tag is to use a special css class named for example hidden:

.hidden {
    display: none;
}

And when you render your HTML code you choose to add this class or not to your tag:

<span class = 'v10 <?php if (strtolower($accountstatus) == 'animaldead') echo '.hidden'; ?>'><span style='color:#FF0000;'>*</span>Inception Date:<br /></span>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.