Posts

Showing posts with the label javascript

File Upload preview

Image
< input type = "file" class = "form-control" name = "productPhoto1" onchange = " preview ('productPhoto1Src'); " />         function preview ( imgSrc ) {           var fileBlob = URL . createObjectURL ( event . target . files [ 0 ]);           $ ( "#" + imgSrc ). attr ( 'src' , test123 );                   }

Email Validation in JS

  function ValidateEmail(mail) { if (/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(myForm.emailAddr.value)) { return (true) } alert("You have entered an invalid email address!") return (false) }   function ValidateEmail(email) { var mailformat = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/; if(email.match(mailformat)){ alert ("valid"); } }

Local Storage in javascript

Image
  localStorage only supports strings. Use JSON.stringify() and JSON.parse() . var names = []; names[ 0 ] = prompt( "New member name?" ); localStorage .setItem( "names" , JSON .stringify(names)); //... var storedNames = JSON .parse( localStorage .getItem( "names" ));

this keyword magic

Image

Date Formate change from Y-m-d to d-m-Y in jquery | javascript | js

Image
                            var dob=$("#dob").val();               var new_dob=dob.split("-").reverse().join("-");               $("#dob").val(new_dob);

jQuery show for 5 seconds then hide

Image
  $( "#myElem" ).show(); setTimeout ( function ( ) { $( "#myElem" ).hide(); }, 5000 );

Delete first character or number from string or number in js

Image
  var s1 = "foobar" ; var s2 = s1.substring( 1 ); alert(s2); // shows "oobar"

JavaScript TypeError – Invalid assignment to const “X”

Image
  This JavaScript exception invalid assignment to const occurs if a user tries to change a constant value. Const declarations in JavaScript can not be re-assigned or re-declared. Message: TypeError: invalid assignment to const "x" (Firefox) TypeError: Assignment to constant variable. (Chrome) TypeError: Assignment to const (Edge) TypeError: Redeclaration of const 'x' (IE) Error Type: TypeError Cause of Error: A const value in JavaScript is changed by the program which can not be altered during normal execution. < script >      const GFG = "This is GFG";      // Error here      GFG = "This is GeeksForGeeks";  </ script >   Output(in console): TypeError: Assignment to const  

Three Types Page Redirect using HTML,Javascript,PHP

Image
  Today we are going to learn how to redirect a page 1)Using HTML <!DOCTYPE html> <html> <head>     <title>Redirect</title>     <meta http-equiv = "refresh" content = "5; url = https://mwtc.in" /> </head> <body>         <h2>Welcome Redirect</h2> </body> </html> 2)Using Javascript <!DOCTYPE html> <html> <head>     <title>Redirect</title> </head> <body>         <h2>Welcome Redirect Javascript</h2> <script type="text/javascript">     window.location.href="http://facebook.com"; </script> </body> </html>   3)Using PHP  <?php header("Location: https://yahoo.com"); ?> <!DOCTYPE html> <html> <head>     <title>Redirect</title> </head> <body>   ...

How to reverse string in vue js

Image
  HTML part : - < div id = "example" > < p > Original message: "{{ message }}" </ p > < p > Computed reversed message: "{{ reversedMessage }}" </ p > </ div >   JS Part : -   var vm = new Vue({ el : '#example' , data : { message : 'Hello' }, computed : { // a computed getter reversedMessage : function ( ) { // `this` points to the vm instance return this .message.split( '' ).reverse().join( '' ) } } })

Indian Mobile No. Validation using Javascript and Jquery

Image
  Type 1 Validation using Javascript : - <!DOCTYPE html> <html> <head>     <title>Indian Mobile No. Validation</title> </head> <body> <h1 style="text-align:center">Indian Mobile No. Validation</h1> <form>     <table align="center" border="30">              <tr>             <td>Mobile No.</td>             <td><input type="text" id="mobile" maxlength="10"  placeholder="Enter Your Mobile No."  /></td>         </tr>                  <tr>             <td colspan="2">                 <input type="button"...

How can I refresh a form JQuery

Image
   Do you have this? < form id = "form" > ..... </ form > If you do, it should work.   $( "#form" )[ 0 ].reset();   If you don't have an "id" for your form tag, you should use    < form > ..... </ form > $( "form" )[ 0 ].reset();  

How to change option text and value of select type using JS

Image
    function changeContent ( ) { var opt= document .getElementById( 'test' ).options[ 0 ]; opt.value = 'box' ; opt.text = 'box' ; }

Form Validation in Pure JS using Form Element Name

 In this post you will learn how to get value from form elements and how to validate whether it filled or not and selected or not . We are trying to show you all basic tags with validation . <!DOCTYPE html> <html> <head>     <title></title> </head> <body>     <h1>Pure Javascript Form Validation using form Element Name</h1>     <form name="myform">         <table align="center" border="30">             <tr>             <td>Gender</td>             <td>                 <input type="radio" name="gender" value="Female" />&nbsp;&nbsp;Female &nbsp;&nbsp;             ...

How to take photo from mobile camera and upload it using php ?

 First we write front end code : - <!DOCTYPE html> <html> <head>     <title>jQM input file capture</title>     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />     <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>     <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> </head> <body>     <div data-role="page" id="page">         <style>             #preview {                 width: 80%; max-width: 300px;             }         ...

How to take photo from camera and its preview in Jquery Mobile ?

 Here you will get code for preview of image captured by your device.   <!DOCTYPE html> <html> <head>     <title>jQM input file capture</title>     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />     <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>     <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> </head> <body>     <div data-role="page" id="page">         <style>             #preview {                 width: 80%; max-width: 300px;             ...