Reputation: 137
I am trying to get the value of input data in a cakephp form so that I can use it in a sql query to auto fill other data. Currently i'm trying to use $this->request->data but it's not showing any results when I change my customer. I want it to display the customer that is selected but currently it's just blank. Not sure if i'm trying to get the data correctly or displaying it incorrectly.
<div class="invoices form large-9 medium-8 columns content">
<?= $this->Form->create($invoice) ?>
<fieldset>
<legend><?= __('Add Invoice') ?></legend>
<?php
echo $this->Form->input('customer_id', ['options' => $customers, 'empty' => true,'id'=>'customers']); ?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
<script>
document.getElementById('customers').addEventListener('change',function(){
alert(<?php echo $this->request->data('customers');
?>)
});
</script>
Upvotes: 2
Views: 61
Reputation: 175
Replace your code with this
document.getElementById('customers').addEventListener('change',function(){
alert(this.value);
});
Upvotes: 1