Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  110] [ 2]  / answers: 1 / hits: 74053  / 12 Years ago, thu, april 26, 2012, 12:00:00

I am trying to make an editor everything working fine till now, but now I need to make a handler which could detect any change made in a div or any content edited in the div



<?php $row=testing content ?>
<!-- my editor section-->
<div id=editor>
<div id=options>
<span><a id=iimg>Insert Image from gallery</a></span>
<span>Upload image to gallery</span>
<span><a id=iheading>Heading</a></span>
</div>
<div id=product_descriptioncontent contenteditable=true><?php echo $row; ?>
</div><!-- viewable editor -->
<input type=hidden name=textareacontent value= id=textareacontent >
<!-- hidden field to submit values -->
</div>
<!-- end of editor section -->
<div id=imc></div> <!-- image gallery loading section -->

<script>
$(document).ready(function(){

$('#iheading').click(function(){
$('#product_descriptioncontent').append('<h1>Heading</h1>');
});

$('#iimg').click(function(){
$('#imc').load('imagegallery.php',function(){
$('#gallery img').on('click',function(){
$('#product_descriptioncontent').append('<img src=http://localhost/sites/site_pics/otherpic/1.png><br>&nbsp;');
});
});
});
$('#product_descriptioncontent').change(function(){
alert(pppp);// how to capture this event
});
});
</script>


I have placed a bit of my code at jsfiddle http://jsfiddle.net/bipin000/UJvxM/1/
thanks for your precious time


More From » jquery

 Answers
148

Do you like this? http://jsfiddle.net/Ralt/hyPQC/



document.getElementById( 't' ).onkeypress = function( e ) {
var evt = e || window.event
alert( String.fromCharCode( evt.which ) )
}​


It's not waiting for a change event, it's kind of pointless.



Instead, it's listening to the onkeypress event. Everytime a user changes the content of this div (by adding a character to it), it triggers the event.



You can also see how to get the character clicked (using String.fromCharCode( evt.which )).



PS: a full jQuery solution for your specific case would be this:



$( '#product_descriptioncontent' ).on( 'keypress', function() {
$( '#your-hidden-input' ).val( $( this ).text() )
// Or
$( '#your-hidden-div' ).text( $( this ).text() )
} )

[#85967] Wednesday, April 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madelyn

Total Points: 449
Total Questions: 100
Total Answers: 100

Location: Seychelles
Member since Fri, May 7, 2021
3 Years ago
madelyn questions
Wed, Jul 28, 21, 00:00, 3 Years ago
Wed, Jul 14, 21, 00:00, 3 Years ago
Sat, Nov 7, 20, 00:00, 4 Years ago
Thu, Sep 3, 20, 00:00, 4 Years ago
;