PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I use a button which resets the contents of my basket, although this code is currently on a php page and therefore the button takes the user to this page to reset the variables. Is it possible to add the code directly to the button to the variables are changed on a mouse click?
//All types of inputs, which values should be reseted
var validInputs = {'hidden': true, 'text': true, 'password': true};
//Handle form submit
function resetForm(form) {
//Get all inputs, which are in the form; textareas and selects are not included
var inputs = form.getElementsByTagName('INPUT');
//Go through all inputs
for(var i=0,j=inputs.length; i<j; i++) {
//If type is in the validInputs list, then
if (validInputs[inputs[i].getAttribute('type')]) {
//set value to nothing
inputs[i].value = '';
}
}
//Prevent defautl behaviour, which is submitting form
return false;
}