user1816914 user1816914 - 1 month ago 6
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"DeleteAppointmentSelected.jsp",'_self',false);
alert('Please Enter a ID before submitting');


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>
<% visit_id=visitsForPatient.getString(1);%>
<%=visit_id %>
<%=visit_date %>
<%=visit_time %>
<%=physician_id %>
<input type="radio" name="deleteVisitID" id="deleteVisitID" value="<%=visit_id %>"/>



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

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


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.