Gusti Aldi Gusti Aldi - 2 months ago 10
HTML Question

How to store span in php variable then used as it tooltip text

I tried to use tooltip for showing the value of span (which is span value to check user availability), so i store span value in php variable on echo it on tooltip tittle but not working.

here's my code

for example label nm_usr is the right tooltip and label log_usr is the variable i tried to echo it

<td><label for="nm_usr">Nama</label></td>
<td><input name="nm_usr" type="text" class="required" minlength="6" id="nm_usr" data-toggle="tooltip" data-placement="right" tittle="Masukkan nama lengkap anda" /></td>
<td><label for="log_usr">Username</label></td>
$tittle = "<span id="usercheck" style="padding-left:10px; ; vertical-align: middle;"></span>";
<td><input name="log_usr" type="text" class="required" minlength="6" id="log_usr" onblur="checkUserName(this.value)" data-toggle="tooltip" data-placement="right" tittle="<?php echo $tittle;?>" />


(1) The attribute that you are looking for is title (not tittle).

(2) You should not put HTML inside the title attribute; it is invalid markup/will not validate.

(3) Your PHP code contains a syntax error:

$tittle = "<span id="usercheck" style="padding-left:10px; vertical-align: middle;"></span>";

Should be replaced with:

$tittle = '<span id="usercheck" style="padding-left:10px; ; vertical-align: middle;"></span>';

If you do wish to have HTML inside tooltips, I would suggest checking out jQuery UI's tooltips feature: