JavaScript Code Mixed-up with PHP Code

Sometimes we need to add something in JavaScript code but unfortunately on other side we are using PHP in same file and the value of some one variable is in PHP code.

Suppose


<?php 

$invoiceno = 2343434; // suppose we have value of one variable in PHP code but we want to use it in JavaScript Code

// so this is JavaScript Code but in the form of PHP while using PHP variable value.

 echo "<SCRIPT LANGUAGE='JavaScript'>
       window.alert('Invoice Posted!')
       window.location.href='sales.php?inv=".$invoiceno."';
       ";  



?>

Google Map (using Html and JavaScript Code)

We developed the following code (from w3school) to view google map on web page. It can be customized.

On Select, Fill The Div with Some Results (with the help of PHP and JavaScript)

Website and web application developers need to select an input to have some results in a div dynamically. So every option of selector would display results in the target div. These results would be scripted in another file.
Now how is it possible?

First need to create a selector having some options and a div which would be filled with the results.


Now JavaScript Code and would declare a file from where the result would be transferred to the target div.


HTML Tag textarea as Text Editor with JavaScript

We use html tag textarea for input of long text e.g. in contact form, we use textarea tag for message (which may have long text), similarly in admission form, we use textarea tag for long description.

Tag textarea syntax are;

<textarea>Some text which is already defined</textarea>

We may need text editor with extra functions to write text with images and some others animations etc. For, we use some JavaScript code to make same html textarea as Text Editor.

<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>

Ajax in Javascript Language

Very important role is contributed by ajax of javascript programming language in development of website and web applications.

Ajax with PHP Language


<!-- HTML code for input (value of which would be used in ajax file), button (which would be used for action of ajax) and div (where the result form ajax file would be pasted). -->
<input class="input_class" type="text" />
<button class="button_class">Click</button>

<div id="div_target" >This is the div where the results from the file (to be interacted by ajax) would be pasted here while replacing the text already herein.</div>

<!-- JavaScript Code -->
<script>
$('.button_class').click(function(){
                var any_var = $('.input_class').val();
                 if(any_var != '' )
                {
                    $.ajax({
                        url:"file_source.php",
                        method:"POST",
                        data:{any_var:any_var},
                        success:function(data)
                        {
                           $("#div_target").value("");
                        }
                    });
                }
                else
                {
                    alert("Put Some Text");
                }
            });
});

</script>

Get Subscribed for E-News Letter and Updates
Our RSS Link
https://primeburg.com/feed/