1

I get this error "Cannot read property 'value' of null", please help to sort this out.I am trying to get the date values and passing to php. Thanks.

<form>
<label for="fromDate">From : </label><input id="from" type="date" id="fromDate" value=""></input>
<label for="toDate">To : </label><input id="to" type="date" id="toDate" value=""></input>

<input type="submit" value="submit"></input>
</form>
<input type="button" onclick="makeAjaxCall();return false;" value="Click to get data"></input>

<script>
function makeAjaxCall() {
    var frm = document.getElementById('fromDate').value;//$('#fromDate').datepicker("getDate");

    var to = document.getElementById('toDate').value;//$('#toDate').datepicker("getDate");
    var postDate ={
        "dateFrom" : frm,
        "dateTo" : to   
    };


  $.ajax({
            type:"POST",
            url:'test.php',
            data: postData,
            success: function(responseData) {

                     //someCode
                   }
    });
}

2 Answers 2

2

You have an input with two id's try using just one

<input type="date" id="toDate"

Instead of:

<input id="to" type="date" id="toDate"
Sign up to request clarification or add additional context in comments.

1 Comment

everyone has his days, don't call yourself like that
1

Use a validator. Some of your elements have multiple id attributes. This is not allowed and is the cause of your problem.

(You probably intended to use a name attribute for the first id attribute in both cases)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.