php - Autofill data gets overwritten by onchange event of javascript -


so facing annoying issue. have form empty field initially. user has option use default set of values choosing radio button 'yes' option.

if user chooses use default set of values fill form fields default set of values using script. goes fine till now.

the problem select drop-down not getting set default value. after debugging found out getting set on change event of js gets fired populating drop down dataset ajax response.

how stop on-change event fired if user not clicked on drop down , changed something.

<!doctype html> <html> <head>     <title></title> </head> <body>  <input type="radio" value="1" name="rdchoice"> yes! set default value <input type="radio" value="0" name="rdchoice"> no! have fill data  <hr>  first name : <input type="text" name="txtfirstname" id="txtfirstname"><br> last name : <input type="text" name="txtlastname" id="txtlastname"><br>  country :  <select onchange="getstate()" id="selcountry">     <option>choose</option>     <option>india</option>     <option>japan</option>     <option>us</option> </select>  </body> </html>  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript">      function getstate()     {         console.log("get state");        }      $(function()     {         $( 'input[name="rdchoice"]:radio' ).change(             function()             {                 if(this.value==1)                 {                     $("#txtfirstname").val("paresh");                     $("#txtlastname").val("gami");                     $("#selcountry").val("india");                 }                 else                 {                  }             }         );      });  </script> 

if user click on select box , getstate called.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -