PDA

View Full Version : Input Validation



JSNoob50
08-07-2011, 10:01 PM
I need to validate a second input in a form from another text input.

I want Input_2 to have a popup alert saying that it needs to be filled out if text input_1 gets an entry in the form. If text input_1 has no entry then there will be no alert for text input_2.

I hope this will be a function inside of a form validation.

Thanks in advance.

keyboard
08-09-2011, 09:27 AM
What type of input is Input_2?

JShor
08-09-2011, 03:57 PM
Well, you'll have to post some code for us to be able to get in detail with this, but this should get you started:



function validateFrm() {
input1 = document.getElementById('input_1');
input2 = document.getElementById('input_2');

if(input1.value != '') {
if(input2.value == '') {
alert('Please fill out input 2');
}
}


The on the onsubmit event in your form, have it invoke the function validateFrm().