How to set a Value of Hidden input from values of another input fields
My other inputs:
<input name="job_no" id="job_no" class="form-control" required>
<input name="cyc_no" id="cyc_no" class="form-control" required>
My hidden field
<input type="hidden" name="id" value="{{request()->input('job_no')}}{{request()->input('cyc_no')}}">
All these inputs in the same form but for some unknown reason value of the id return null. Any thoughts??
Dual binding doesn't work here, you have to do this with JavaScript manually.
<form>
<input name="job_no" id="job_no" class="form-control" required />
<input name="cyc_no" id="cyc_no" class="form-control" required />
<input type="hidden" id='hidden' />
<input type='button' id='submit' value='Submit' />
</form>
</script>
let form = document.querySelector('form');
let hiddenInput = document.querySelector('#hidden');
let submitButton = document.querySelector('#submit');
let job_no = document.querySelector('#job_no').value;
let cyc_no = document.querySelector('#cyc_no').value;
hiddenInput.value = job_no + cyc_no;
submitButton.addEventListener('click', function() {
form.submit();
});
</script>
Thank you very much for your help @sergiu17. Can I do this in the store function in controller.
Like This:
$job = new Job;
$job->id = $request->input('job_no')+input('cyc_no');
$job->job_no = $request->input('job_no');
$job->cyc_no = $request->input('cyc_no');
$job->save();
Hi @sergiu17
I was able to get rid of the hidden input and set the id value in the controller itself.
$job->id = $request->input('job_no') . $request->input('cyc_no');
But nevertheless, I very much value your approach and once again thank you very much for help.
Please or to participate in this conversation.