There is only one window.onload per page. Each successive one that your PHP loop creates overwrites (in memory only) the previous one. So, the last one in the series would still work. If that's happening, here is another way of doing it without window.onload, that should work. Replace the part from your post with this:
Code:
<?
if(isset($_POST['qty'])){
$qty = $_POST['qty'];
} else {
$qty = 'qty';
}
?>
<input type="text" name="colour" id="inp<?=$i?>" value="<?=$qty?>" class="contact" style="width:15px; height:14px; font-size:9px;color:#666;float:left;margin-top:2px">
<script type="text/javascript" defer>
;(function(){
var inp<?=$i?>=document.getElementById('inp<?=$i?>'), // Set the input element's ID.
text='<?=$qty?>'; // Default input text's value. This should match on the value of your value attribute.
inp<?=$i?>.onfocus = function()
{this.style.color='#222';this.value=(this.value==text)?'':this.value;}
inp<?=$i?>.onblur= function()
{
if(this.value=='')
{
this.value=text;
this.style.color='#aaa';
}
else this.value;
}
})();
</script>
However, aside from the window.onload problem, the highlighted above looks wrong to me. It should perhaps be replaced by:
Code:
inp<?=$i?>.onblur= function()
{
if(this.value=='')
this.value=text;
this.style.color='#aaa';
};
or maybe:
Code:
inp<?=$i?>.onblur= function()
{
if(this.value==''){
this.value=text;
this.style.color='#aaa';
};
};
But if it works for you 'as is', I wouldn't worry about it too much. It's just that this line from your version:
doesn't look like it would do anything, and may even cause an error.
Bookmarks