0

I am using HTML and PHP for this scenario, the code follows :

echo"<td>".'<div class="checkbox">
              <label>
                <input type="checkbox" name="total" id ="total" value="'.$test['req_tot'].'" " onchange="checkTotal()">'.$test['req_tot'].'
              </label>
            </div>'."</td>";

Javascript:

 function checkTotal() {
      alert(document.getElementById("total.value"));
    }

Now, when I click the checkbox, instead of displaying the value $test['req_tot'] from database it shows NULLenter image description here

N.B :- Values form database are being displayed properly

chris85
  • 23,846
  • 7
  • 34
  • 51
mustangDC
  • 945
  • 1
  • 12
  • 33
  • 1
    Shouldn't it be `alert(document.getElementById("total").value)`? I see no element named `total.value`, if you do have that element you still need to `value` selector to get the value. – chris85 Oct 23 '16 at 16:15
  • Possible duplicate of [JavaScript: how to get value of text input field?](http://stackoverflow.com/questions/11563638/javascript-how-to-get-value-of-text-input-field) – chris85 Oct 23 '16 at 16:17
  • your edited comment is correct not the `.value()`, anyways thanks though – mustangDC Oct 23 '16 at 16:19
  • 1
    Yea, I'm not much of a JSer, PHP tag brought me. I usually jQuery which is why I put that first (although in jquery it was wrong too `val()`). – chris85 Oct 23 '16 at 16:21

1 Answers1

2

Your javascript is not correct.

function checkTotal() {
          alert(document.getElementById("total").value);
        }
BugHunter
  • 1,194
  • 2
  • 9
  • 15