Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

August 11, 2019

FormData.delete() and FormData.set() do not support Internet Explorer

Problem: All methods of FormData do not work/compatible with Internet Explorer. The only method that is successful is 'append'. but suppose you want to override values of specific keys but in that scenarios 'set' and 'delete' methods will not work on Internet Explorer.

Solution: You may use below code that will work on IE.

var form = $('form')[0];
var formData = new FormData();

var inputs = form.getElementsByTagName('input'); //for input box

var inputsList = Array.prototype.slice.call(inputs);
inputsList.forEach(
  function (i) {
     if (i.name !== 'excludedName') {
          formData.append(i.name, i.value);
     }
   }
);
formData.append('excludedName', 'value you want to set');

Note: for 'select' and 'textarea' use: 
var selects = form.getElementsByTagName('select');
var textareas = form.getElementsByTagName('textarea');

April 23, 2016

Disable or enable input field using jQuery and JavaScript

JavaScript :
We can disable or enable an input box by setting property true or false respectively by using below code.
Code of input box
Name: <input type="text" id="myName">

To Disable input box.
document.getElementById("myName").disabled = true;

To Enable input box.
document.getElementById("myName").disabled = false;

jQuery :
If you are using jQuery 1.6+ then you should use the .prop() function to disable or enable input field.
$("input").prop('disabled', true);
$("input").prop('disabled', false);

Above code will disable all the input fields, if you want to disable or enable particular field, then you should use class or id of that particular input field.
Name: <input type="text" id="myName" class="myName"> 
$("#myName").prop('disabled', true);  // using id of input box
$(".myName").prop('disabled', false); // using class of input box

If you are using jQuery 1.5 or below then you should use the .attr() function.
To disable input field:
$("input").attr('disabled', 'disabled');

To enable input field:
$("input").removeAttr('disabled');

There is also .removeProp like .removeAttr in jQuery 1.6 but we should not use it because once you use removeProp you can not again disable it.

March 20, 2016

Jquery : Show label value on alert and browser console

Here, we are working with label, button and pop up message box where we are showing label value in message box on same page on submit button click using jquery.

index.jsp
console.log displays value(s) on browser console (Press F12 on browser then click on console tab to see console.log output) and alert on message box.

Jquery Download Link : http://jquery.com/download/
 
Output:

Also Read : How to show textbox value on message box with Jquery on button click

December 8, 2015

Check for Float value on keypress using JQuery

Following is script by which you can put check for float value.





html input field on which you want to put check for float value:
 <input class="checkfloat" type="text">  

Script for Float Value check:
 $(".checkfloat").on("keypress keyup",function (event) {  
     $(this).val($(this).val().replace(/[^0-9\.]/g,''));  
     if ((event.which != 46 || event.which == 8 || event.which == 9 || $(this).val().indexOf('.') != -1)   
               && ((event.which < 48 || event.which > 57))) {  
       event.preventDefault();  
     }  
   });  

November 5, 2013

How to show textbox value on message box with Jquery on button click

Here, we are working with textbox, button and pop up message box where we are showing textbox value in message box on same page on search button click using jquery.

index.jsp
put this script inside <head> tag
put this code inside <body> tag

Output:


Also Read : Jquery : Show label value on alert and browser console

Disclaimer

We shall not be liable for the improper or incomplete transmission of the information contained in this communication nor for any delay in its response or damage to your system. We do not guarantee that the integrity or security of this communication has been maintained or that this communication is free of viruses, interceptions or interferences. Anyone communicating with us by email accepts the risks involved and their consequences. We accept no liability for any damage caused by any virus transmitted by this site.