javascript - how to use single button click to change placeholder and capture new data on same button click event -


<div id="abc" class="first">            <input type="text" placeholder="number" id="no" class="contact">            <input type="text" placeholder="pass"  id="pass" class="password">  <div class="btn1" role="group">          <button type="button" onclick="change()" class="btnregi">register          </button>   </div>        ----------     javascript function     var entry=0;     function change()         {           if(entry==0)       {        document.getelementbyid("no").placeholder = "enter user name...";        document.getelementbyid("pass").placeholder = "enter user password";        entry++;       }        else         {           var newuser=document.getelementbyid("no").value;           var newpass=document.getelementbyid("pass").value;           alert("you entered new username"+newuser);           alert("you entered new password"+newpass);        }    

i want change placeholder values onclick event , again same button click , method want fetch input data. attached code wont working.

you had misspelled getelementbyid in these 2 lines. apart code seems working fine me.

var newuser = document.getelementbyid("no").value; var newpass = document.getelementbyid("pass").value; 

var entry = 0;    function change() {      if (entry == 0) {      document.getelementbyid("no").placeholder = "enter user name...";      document.getelementbyid("pass").placeholder = "enter user password";      entry++;    } else {      var newuser = document.getelementbyid("no").value;      var newpass = document.getelementbyid("pass").value;      alert("you entered new username: " + newuser);      alert("you entered new password: " + newpass);    }  }
<div id="abc" class="first">  <input type="text" placeholder="number" id="no" class="contact">  <input type="text" placeholder="pass" id="pass" class="password">  <div class="btn1" role="group">    <button type="button" onclick="change()" class="btnregi">register           </button>  </div>


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -