javascript - Using jQuery JSON function to populate textarea when a specific dropdown item is selected -


i might sound noob, me this?

i have form dropdown select , within lot of text area boxes.

what need:
when specific option selected, i'd populate text area text (using json).

code:

html

<label>name</label> <select> <option value="0" data-num="">name lastname</option> <option value="1" data-num="">name lastname</option> <option value="2" data-num="">name lastname</option> <option value="3" data-num="">name lastname</option> </select>   <textarea name="name"></textarea> <textarea name="applicant"></textarea> <textarea name="applicant_en"></textarea> <textarea name="email"></textarea> <textarea name="vat"></textarea> <textarea name="rc"></textarea> 

json data

{ "id":["1","2"], "name":["john doe","john notdoe"], "applicant":["lorem ipsum","second"], "applicant_en":["one","two"], "email":["mail","mail_two"], "vat":[61388963,4684645456], "rc":["123456/0123","87986454/554"] }" 

i've tried something, gave up.. me, please?

<select id="some_id"> <option value="0" data-num="">name lastname</option> <option value="1" data-num="">name lastname</option> <option value="2" data-num="">name lastname</option> <option value="3" data-num="">name lastname</option> </select> 

js:

$("#some_id").on('change',function(){     if($(this).val()==1){         $("input[name='applicant']).val("fetched json");      }    ///else continue other values }) 

edit : provide id or class html.

<textarea name="applicant" id="applicant"></textarea> 

in js :

populate('#myform', $.parsejson(data));    function populate(strformid,jsondata){      $(strformid+' #applicant').val(jsondata.applicant[0] +' '+jsondata.applicant[1]);  //do in same way other dom element. } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -