Passing PHP Variable to Javascript Troubleshooting -


this followup insert input text after select change dynamic ids fiddle

i've been troubleshooting creating alerts.

<script type="text/javascript">   var employeeid = <?= json_encode($addtech['employeeid']) ?>;   var selectid = "#duration-" + employeeid;   var textid = "#promdate-" + employeeid;   var displaydate = "<?= $displaydate ?>";   $(selectid).change(function(){ //       $(textid).val(displaydate);     try {       alert(employeeid);     } catch(err) {       document.getelementbyid("demo").innerhtml = err.message;     }   }); </script> 

in source, see first entry var employeeid = 1; when make select change, 47 in alert box. there around 20 employees in form; employeeids correct in source, alert returns 47 them all.

any clues?

thanks.

the variable getting in php encoded in json. access javascript variable must decode it:

var employeeid = <? echo json_encode($addtech['employeeid']) ?>; employeeid = json.parse(employeeid); 

however, if employeeid integer value , not object not need encode , can pass value directly:

var employeeid = <? echo $addtech['employeeid'] ?>;


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -