Posts

Showing posts with the label js

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 );                   }

Get selected value from react js functional component

Image
  // App.js import React, { useState } from "react"; import { Dropdown, Option } from "./Dropdown"; export default function App() {   const [optionValue, setOptionValue] = useState("");   const handleSelect = (e) => {     console.log(e.target.value);     setOptionValue(e.target.value);   };   return (     <div>       <h1>Which service are you interested in?</h1>       <Dropdown         formLabel="Choose a service"         buttonText="Send form"         onChange={handleSelect}         action="https://jsonplaceholder.typicode.com/posts"       >         <Option selected value="Click to see options" />         <Option value="Option 1" />         <Option value="Option 2" />         <Option...

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"); } }

File size and file type finding in js(javascript)

Image
    < script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" > </ script > < form action = "upload.php" enctype = "multipart/form-data" method = "POST" id = "uploadform" > < input id = "openFile" name = "img" type = "file" /> </ form >   <script> $( document ).ready( function ( ) { $( '#openFile' ).on( 'change' , function ( evt ) { console .log( this .files[ 0 ].size); ///File size      var filename=   this .files[ 0 ];      extension = filename.split( '/' ).pop();    // File Type Extension       }); });   </script>    ------------------------------------------------------------------------------- <form id="form1" runat="server"> <input type='file' id="imgInp" /> <img id="blah" src="#" alt="your image...

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" ));

Create json data and use it as dynamic data using jquery in Hindi | Codi...

Image

Set value in radio button by its name

Image
  function RadionButtonSelectedValueSet ( name, SelectdValue ) { $( 'input[name="' + name+ '"][value="' + SelectdValue + '"]' ).prop( 'checked' , true ); }

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"

How to use Formdata for file upload and data save using ajax

  var form = $( '#fileUploadForm' )[ 0 ]; var data = new FormData(form); data.append( "CustomField" , "This is some extra data, testing" ); $( "#btnSubmit" ).prop( "disabled" , true ); $.ajax({ type : "POST" , enctype : 'multipart/form-data' , url : "upload.php" , data : data, processData : false , contentType : false , cache : false , timeout : 600000 , success : function ( data ) { console .log(); },

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  

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 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;             ...