Answers for "SCRIPT.JS"

PHP
19

how to use javascript in html

<!-- include an external javascript document -->
<script src="myJavaScript.js" charset="utf-8"></script>

<!-- JavaScript inside html element -->
<script>
  console.log("This is JavaScript");
</script>
Posted by: Guest on October-29-2020
5

js script

<script src="javascript.js"></script>
Posted by: Guest on July-07-2020
1

script js

<script type="text/javascript" src="monscript.js"></script>
Posted by: Guest on March-29-2020
2

js script

<script src="javascript.js"></script>
Posted by: Guest on July-07-2020
2

script tag in html

<script>
  // Write JS here
</script>

<script src="link/to/js/file.js"></script>
Posted by: Guest on October-20-2020
0

SCRIPT.JS

$(document).ready(function(){
	// When user clicks on submit comment to add comment under post
	$(document).on('click', '#submit_comment', function(e) {
		e.preventDefault();
		var comment_text = $('#comment_text').val();
		var url = $('#comment_form').attr('action');
		// Stop executing if not value is entered
		if (comment_text === "" ) return;
		$.ajax({
			url: url,
			type: "POST",
			data: {
				comment_text: comment_text,
				comment_posted: 1
			},
			success: function(data){
				var response = JSON.parse(data);
				if (data === "error") {
					alert('There was an error adding comment. Please try again');
				} else {
					$('#comments-wrapper').prepend(response.comment)
					$('#comments_count').text(response.comments_count); 
					$('#comment_text').val('');
				}
			}
		});
	});
	// When user clicks on submit reply to add reply under comment
	$(document).on('click', '.reply-btn', function(e){
		e.preventDefault();
		// Get the comment id from the reply button's data-id attribute
		var comment_id = $(this).data('id');
		// show/hide the appropriate reply form (from the reply-btn (this), go to the parent element (comment-details)
		// and then its siblings which is a form element with id comment_reply_form_ + comment_id)
		$(this).parent().siblings('form#comment_reply_form_' + comment_id).toggle(500);
		$(document).on('click', '.submit-reply', function(e){
			e.preventDefault();
			// elements
			var reply_textarea = $(this).siblings('textarea'); // reply textarea element
			var reply_text = $(this).siblings('textarea').val();
			var url = $(this).parent().attr('action');
			$.ajax({
				url: url,
				type: "POST",
				data: {
					comment_id: comment_id,
					reply_text: reply_text,
					reply_posted: 1
				},
				success: function(data){
					if (data === "error") {
						alert('There was an error adding reply. Please try again');
					} else {
						$('.replies_wrapper_' + comment_id).append(data);
						reply_textarea.val('');
					}
				}
			});
		});
	});
});
Posted by: Guest on August-08-2020

Code answers related to "SCRIPT.JS"

Browse Popular Code Answers by Language