Im trying to delete content of some elements based on the drop down selection. I have tried this code the alert shows the new value is empty but when I save it, targeted element still has content.
Here's my code:
var res = document.getElementById("select-result").value; //alert(res); function clearValues(id, inputType) { var td = document.getElementById(id); if (td != undefined || td != null) { var res = td.getElementsByTagName(inputType)[0].value; alert(res); // returns the content of element if (res != "") { res = ""; alert("New res value: " + res); //returns empty } } } Note: If i manually remove content of the target element it saves it as empty. That's puzzling
for me. What's the difference shouldn't javascript make things easier rather than manually emptying fields.
reset()method to reset your form. Of course this will return all form elements back to their original value.ifcondition, alwaysresis expect to be empty. so you don't need to check value of that element. Just dores = ""in your if condition.