How to set a timer in JavasScript

If we want to call a function every 10 seconds using JavaScript we can accomplish it by implementing the following piece of code window.setInterval('yourfunction()', 1000); function yourfunction(){ alert('test'); } With the code above every 10 seconds a JavaScript function with the name yourfunction will be called that will prompt an alert. window.setInterval = Evaluates an expression each time a certain number of seconds have elapsed

March 21, 2018 · 1 min · 65 words · icarnaghan

How to submit an HTML Form using JQuery

For example you have a form with id “myform” <form id="myform" action="submit.php"> <input type="text" value="This is a test form" /> <input type="button" id="mybutton" value="Save" /> </form> Now when the button with id “mybutton” is clicked we want to submit the form using the JQuery submit() function which executes each time the specified event is triggered. The code looks like the below <script type="texxt/javascript"> $('#mybutton').click(function() { $('#myform').submit(); }); </script> Now whenever the Button with id “mybutton” is clicked the form will submit to the submit.php page.

March 21, 2018 · 1 min · 85 words · icarnaghan

How to suppress JavaScript errors

Create a JavaScript function called suppressJS() function suppressJS(){return true;} Then within the head tags add the following code window.onerror=suppressJS; Your complete code will look like this <script type="text/javascript"> <!-- function suppressJS(){return true;} window.onerror=suppressJS; //--> </script>

March 21, 2018 · 1 min · 35 words · icarnaghan

How to upload a file via Ajax using a form with JQuery and PHP

Click here to download JQuery files Answer: Create a new file called form_upload.php Include JQuery and the JQuery Form Plugin between the head tags in the form_upload.php file. {codecitation class=“brush: html;”} Ajax File Uploader Include the following code between the head tags underneath the JQuery Form Plugin include {codecitation class=“brush: javascript”} <!– $(document).ready(function() { var options = { target: ‘#message’, //Div tag where content info will be loaded in url:‘upload.php’, //The php file that handles the file that is uploaded beforeSubmit: function() { $(’#uploader’).html(’’); //Including a preloader, it loads into the div tag with id uploader }, success: function() { //Here code can be included that needs to be performed if Ajax request was successful $(’#uploader’).html(’’); ...

March 21, 2018 · 2 min · 345 words · icarnaghan

How to use JQuery to make a field Read Only

Say you have a input text field as below <input type="text" name="inputField" id="inputField" /> As soon as the page has finished loading we will make use of JQuery to make the input field Read Only so that the field can’t be edited by the user. We do it like this <script type="text/javascript"> jQuery(document).ready(function($){ $('#inputField').attr('readonly', 'readonly'); }) </script>

March 21, 2018 · 1 min · 57 words · icarnaghan

Javascript: Creating a basic popup window

Javascript gives you the ability to open new windows in you’re browser. You’ll also have the ability to run any code in these windows, you could even have actions in the one window that will affect another window. The following statement is used to open up a basic popup window window.open(“popup.html”,“PopUp Window”,“menubar=no,width=600,height=360,toolbar=no”); The syntax for the example above is to first specify the web page to load into the window, then the title of the window. And last we specify the options for the window. ...

March 21, 2018 · 2 min · 297 words · icarnaghan