PDA

View Full Version : Duno what to call it :P



L?KE
26-11-2008, 08:01 PM
I've got this JS function for my forms when they are focused on and off. Say I fiddle with it, and change function names or whatever is it logical to change:



<input type="text" name="text" value="Text Input" class="normal" onFocus="focusIN(this)" onBlur="blurIN(this)" />
to:



<?php

$do = "onFocus=\"focusIN(this)\" onBlur=\"blurIN(this)\"";

?>
<input type="text" name="text" value="Text Input" class="normal" <?= $do ?> />
..?

Or is there an easier way of doing so, or should I just not bother :P
(Baring in mind that it will be used for more than one form item)

Iszak
26-11-2008, 10:04 PM
I prefer seperating HTML and Javascript because it allows me to manage it easier I also prefer javascript frameworks because they are more cross-browser compatible. You can use the following..


$(document).ready(function(){
$('input[name="text"]').focus(function(){
// Do something when focused
});

$('input[name="text"]').blur(function(){
// Do something when blurred
});
});
in conjunction with


<input type="text" name="text" value="Text Input" class="normal">
Now to me that's an easier way to do it and an easier way to manage too. But it all comes down to preference, also just do you know you need the jQuery library for my example to work. I hope this helps answer your question.

Live example - http://pastebin.me/492dc7be599ec

L?KE
27-11-2008, 05:26 PM
Hm, I might give that a go. Will probably be useful for anything else I add on. Cheers, +rep.
[Gota spread]

Want to hide these adverts? Register an account for free!