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

shahr's avatar
Level 10

TypeError: inputDate is null

I want to pass date to inputDate.

	<date-picker type="date" id="date" name="date" value="{{ old('date') }}" format="jYYYY-jMM-jDD" v-model="date"></date-picker>

script

<script>
    let product_id = "{{ $product->id }}";
    let warranty_id = "{{ $warranty->id }}";
    const app = new Vue({
        el: '#app',
        data: {
            dates: [],
            products: [],
            warranties: [],
            date: '',
            product_id: product_id,
            warranty_id: warranty_id,
        },
        watch: {
            date(newDate) {
                axios.get('{{ route('products.warranties.types.create', [$product, $warranty]) }}', {
                    product_id: this.product_id,
                    warranty_id: this.warranty_id,
                })
                    .then(response => {
                        console.log(JSON.stringify(response.data));
                        const showType = document.getElementById('showType');
                        const inputDate = document.getElementById('inputDate');
                        showType.innerHTML = response.data;
                        inputDate.textContent = newDate;
                    })
                    .catch(error => {
                        console.log(error);
                    });
            }
        },
        components: {
            DatePicker: VuePersianDatetimePicker
        }
    });
</script>

blade

<input type="text" name="inputDate" id="inputDate">
0 likes
1 reply
LaryAI's avatar
Level 58

The error "TypeError: inputDate is null" is occurring because the element with id "inputDate" is not found in the HTML document. To fix this, add the element with id "inputDate" to the HTML document.

HTML:

<input type="text" name="inputDate" id="inputDate">

If you want to set the value of the input field to the selected date, you can use the value property instead of the textContent property.

JavaScript:

const inputDate = document.getElementById('inputDate');
inputDate.value = newDate;

Please or to participate in this conversation.