JavaScript - jQuery - Ajax

Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.

  1. » PloMar
    Hello,
    Is it possible to display the content of a Div in full screen window with JavaScript?
    Last post » Admin
    Hi,
    There is fullscreen API in JavaScript, you can use the requestFullscreen() method to display a HTML element in full screen mode, documentation:...


  2. » PloMar
    Hello,
    I have the following code that sends form data with Ajax to a php script. It works, but after the form data is sent, the value added in the...
    Last post » Admin
    Hello,
    You can use the following JavaScript code (in the "success" section of your Ajax function) when the data have already been sent, to...


  3. » PloMar
    Hello
    I have the following code to send form data to a php script, with jQuery Ajax, withouut reloading the page.
    But, when I press the Submit button...
    Last post » Admin
    Hi,
    You have to call preventDefault() method to stop default action.
    <script>
    $(document).ready(function(){...


  4. » PloMar
    Hello,
    I want to display a file (image) in canvas before it is uploaded.
    The preview action in canvas should be executed all in the browser without...
    Last post » Admin
    Hi,
    You can use URL.createObjectURL() on the File from your <input> to generate a blob object URL.
    Generated URL will be like:...


  5. » PloMar
    Hello,
    I have a canvas element and a form with a text box and a button. I want to be able to put an image url into the text box, and after click on...
    Last post » Admin
    Hi,
    You can use this script. When click on the button, it adds the image from URL in page (into a Div, #pic1), then, the function addCnvImg() gets...


  6. » PloMar
    Hi,
    I have the following code:
    <img src="image.png" alt="Image" onclick="test(data)" />

    <script>...
    Last post » Admin
    Hi,
    If the argument is a string, you should add it between quotes, like this:
    <img src="image.png" alt="Image"...


  7. » PloMar
    Can I make the content of a html div to be editable?
    For example I have the following code:
    <div id="edit1">Content that can be...
    Last post » MarPlo
    To make the content of a html element to be editable, just add the: contentEditable="true" attribute in that tag. It can be used in almost...


  8. » PloMar
    Hello
    I have an input text field to which i want to display a tooltip with a html table, when the mouse is over the input field.
    How can i make it...
    Last post » Admin
    Hello
    Set "position:relative;" to the parent container (it is important for absolute position), then set "position: absolute;",...


  9. » PloMar
    How can I refresh the page after a specified time?
    I have a html table with data from server. These data are changed to every 3 minutes, so I want to...
    Last post » MarPlo
    You can use the reload() function added in setTimeout().
    <script>
    // refresh page after 3 min. (true to load from server, not from cache)...


  10. » PloMar
    How can I parse the array items in reverse order, in JavaScript?
    I have a Div and an array with numbers in JS code, like this:
    <div...
    Last post » MarPlo
    The simplest way is to use a reverse for() loop (with "i--").
    See this example:
    <div id="dv1"></div>
    <script>...


  11. » PloMar
    How to add (append) text in textarea using jquery without removing previous text?
    I have this code, but it only works for first time, when i change...
    Last post » MarPlo
    Inside the dom the value and text attributes are stored separately. When you use append the text is appended but the value is blanked because it is...


  12. » PloMar
    Hi
    I'm drawing text in an HTML5 canvas on top of an image. I want to calculate a font size so that the string will span 200 pixels width.
    So...
    Last post » MarPlo
    The fillText() method has an optional fourth argument, which is the max width to render the string.
    - MDN's documentation says:
    maxWidth - the...


  13. » PloMar
    Hello all
    Anyone know how to calculate the number of characters that will fill one line of a div with a fixed width (for example 200px), using...
    Last post » MarPlo
    Hi,
    You can use this formula to get the width of the line for a given number of characters (CPL):
    Width = CPL * (font-size / font-constant)
    - CPL...


  14. » PloMar
    I use this code to animate position of a Div when is hovered. I move it with 2500 animation speed.
    How do I change speed of this animation to 800,...
    Last post » Admin
    Try with the dequeue() function (Execute the next function on the queue for the matched elements).
    <div id="dv">Animate...


  15. » PloMar
    Let say I have this html:
    <div id="parent">
    <div id="c1">Content child 1</div>
    <p...
    Last post » Admin
    Try with the ">" selector, it refers to the direct childen.
    1. Example get array with the ID of all direct children.
    <div...


  16. » PloMar
    How can I use JavaScript /jQuery to follow the mouse cursor with a DIV in the whole page?
    Last post » Admin
    If you want this effect with pure JavaScript, you can use this code:
    <style>
    #div_moving {
    position: absolute;
    width: 140px;...


  17. » PloMar
    I'm playing with jQuery. Now I test the trigger() method.
    I try to trigger a custom method and pass two additional arguments (an object and a...
    Last post » Admin
    When you pass multiple arguments with trigger(), and those arguments aren't a number or a string, you should pass all the additional arguments into...


  18. » PloMar
    I have a Select box and options with IDs of the rows from a MySQL table.
    In that form there are 3 text fields.
    Now, when I select an option from the...
    Last post » Admin
    To make that script you need to know how to work with JavaScript /Ajax and with data in JSON format.
    1. Register an "onchange" event to the...


  19. » PloMar
    I have an object like this in javascript:
    var obj = {
    prop1: 'val 1',
    prop2: 'val 2',
    prop3: 'val 3'
    };
    What is the best way to...
    Last post » Admin
    You can use the built in Object.keys method:
    var obj = {
    prop1: 'val 1',
    prop2: 'val 2',
    prop3: 'val 3'
    };

    var props =...


  20. » PloMar
    I have an object like this in javascript:
    var obj = {
    prop1: 'val 1',
    prop2: 'val 2',
    prop3: 'val 3'
    };
    What is the best way to...
    Last post » Admin
    To remove a property from a javascript object, you can use the "delete" instruction.
    Example:
    var obj = {
    prop1: 'val 1',
    prop2:...


  21. » MarPlo
    I have a html table and a button, like this:
    <table id="tb_id" border="1">
    <tr>
    <th>Website</th>...
    Last post » Admin
    To append a row in a html table, use this syntax:
    $('#table_id > tbody:last').append('<tr>...</tr>');
    And to...


  22. » MarPlo
    I'm trying to dynamically add and remove items with jQuery when I press the Append /Remove buttons.
    This is the html code:
    <ul...
    Last post » Admin
    Use the append() and remove() jquery methods, like in this example:
    <ul id="lists">
    <li>List Item 0</li>
    </ul>...


  23. » MarPlo
    I need to serialize an object to JSON in JavaScript. Is there a "standard" way to do this?
    I have an array defined something like this:...
    Last post » Admin
    Use the JSON object methods.
    - To convert an object to a string, use JSON.stringify() :
    var json_string = JSON.stringify(your_object, null, 2);...


  24. » MarPlo
    I want to do something like this:
    $(".chkox").checked(true);
    Or:
    $(".chkox").selected(false);
    I wish to set...
    Last post » Admin
    Use the prop() method.
    $('.chkbox').prop('checked', true); // checking
    $('.chkox').prop('checked', false); // unchecking
    And if you...


  25. » MarPlo
    Is it posible to run a php function through a javascript function?
    Something like this:
    <div id="php_code">Here will be added the...
    Last post » Admin
    PHP is evaluated at the server; javascript is evaluated at the client-side/browser, thus you can't call a PHP function from javascript directly. But...