I have a form with input fields where is possible to write values (width, height, margin, padding, etc.). I want "live preview" of what I'm changing. I tried something like:
Code:
<script>
$("#width").live("hover", function () {
var valWidth = $(this).val();
$("#test").css( "width", $("#test").width(valWidth) ).change();
});
$("#height").live("hover", function () {
var valHeight = $(this).val();
$("#test").css( "height", $("#test").height(valHeight) ).change();
});
...
</script>
but it reset after choosing another input field. Any help will be appreciated.
If #width, #height,.. are associated with an input field (text) then the event you should be handling are the "change".
Assuming the "#test" element is used for the preview:
$("#width").live("change", function () {
var valWidth = parseInt($(this).val());
if(!isNaN(valWidth)){
$("#test").css( "width", valWidth);
}
});
Your script resets after choosing another input field because of the hover
I used "hover" to show preview after putting new value in input field (without leaving this field). Is there any way to could do it (maybe onkeypress or something)?
Bookmarks