Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SupunSam's avatar

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??

0 likes
4 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

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>
SupunSam's avatar

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();
SupunSam's avatar

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.

1 like

Please or to participate in this conversation.