user1816914 user1816914 - 2 months ago 7
Javascript Question

Cannot set property value of null

I'am a newbie here trying to set a value of a hidden field on button click fetching value from a radio button. For some reason I'am able to alert the value but while assigning, it always gives me null.

Please help.

Thanks in advance.

<script type="text/javascript">
function deleteCheck(){
var values = document.getElementById("deleteVisitID").checked;

if (values) {
var hiddenInput = document.getElementById('deleteIDValue');
*hiddenInput.value=document.getElementById("deleteVisitID").value;* <---- throws error

window.open("DeleteAppointmentSelected.jsp",'_self',false);
}else{
alert('Please Enter a ID before submitting');
}
}

</script>





on the form

<table border="1">
<tr><th>visit_id</th><th>visit_date</th><th>visit_time</th><th>physician_id</th><th>Delete Visit</th></tr>
<%
while(visitsForPatient.next()){
%><tr>
<td>
<% visit_id=visitsForPatient.getString(1);%>
<%=visit_id %>
</td>
<td>
<%visit_date=visitsForPatient.getString(2);%>
<%=visit_date %>
</td>
<td>
<%visit_time=visitsForPatient.getString(3);%>
<%=visit_time %>
</td>
<td>
<%physician_id=visitsForPatient.getString(4);%>
<%=physician_id %>
</td>
<td>
<input type="radio" name="deleteVisitID" id="deleteVisitID" value="<%=visit_id %>"/>
</td>


</tr>

<%

}
%></table><input type="hidden" name="deleteIDValue"/>

Answer
<input type="hidden" name="deleteIDValue"/>

Needs to have an ID attribute:

<input type="hidden" name="deleteIDValue" id="deleteIDValue"/>

For this line in your script to work:

document.getElementById('deleteIDValue')

At the moment, you are trying to find an element with ID deleteIDValue which does not exist on the page. Therefore, you cannot call .checked or .value on a non-existent object, which is where you are getting the error.

Comments