Page 1 of 1

changing <a> value depending on the <?php condition?>

Posted: Sun Jan 15, 2012 11:15 pm
by preenzraven
I am just wondering if this is possible because I am using a drop down login form when I click Login Link but when I click Login this will change to Close since Dropdown Login is shown and if closed then Close link will go back to its original value Login.

Code: Select all

			<li><a rel="#fe4902" href="#" class="btn-slide">
			<? if($log==false)
			{
			$log=true;
			?>Login<?
			}elseif($log==true)
			{
			$log=false; 
			?>Close<?
			}?>
			</a></li>
this is the code I use. and the output is <a>LoginClose</a> instead of <a>Login</a> or <a>Close</a> while opened.

Hope someone helps =)

Re: changing <a> value depending on the <?php condition?>

Posted: Mon Jan 16, 2012 2:53 am
by social_experiment
Yes it's possible to change the text value of the link;

Code: Select all

<li>
<a rel="#fe4902" href="#" class="btn-slide"><?php ($log == false) ? $text = 'Login' : $text = 'Close'; echo $text; ?></a>
</li>
Don't use short php tags (<? ?>) rather go for <?php and close with ?>

Hth

Re: changing <a> value depending on the <?php condition?>

Posted: Mon Jan 16, 2012 3:56 am
by twinedev
Just curious the point of toggling the value of $log

Code: Select all

<li><a rel="#fe4902" href="#" class="btn-slide"><?php echo ($log==FALSE) ? 'Login' : 'Close'; ?></a></li>
-Greg

Re: changing <a> value depending on the <?php condition?>

Posted: Mon Jan 16, 2012 4:05 am
by social_experiment
@twinedev Good use of the echo and ternary operator; i'll definitely use this format in future. I used to get tripped up by adding an echo in die 2nd and 3rd expressions so i did it in the way i posted