mardi 4 août 2015

JavaScript button on click navigate to another HTML page

I was having some problem with the HTML and JavaScript validation. So basically I got multiple fields and I will perform a validation before moving to another HTML page. Here is the code:

<fieldset>
    Name* <input id="name" type="text" name="name"> </input>
    NRIC/Passport No* <input id="nric" type="text" name="nric" > </input>
    <input id="btnSubmit" type="submit" value="Pay now!" onclick="validate()"/> 
</fieldset>

My Javascript:

function validate(){
var name = document.getElementById('name').value;
var nric = document.getElementById('nric').value;
var submit = document.getElementById('btnSubmit').value;

if(name == null || name == ""){
    alert('Please enter your name. Do not leave it blank before proceed to the next field.');
}
else if(nric == null || nric == ""){
    alert('Please enter your NRIC. Do not leave it blank before proceed to the next field.');
}else{
    window.location.href = '../successful.html';
}
}

I tried to perform a validation before moving to successful.html. The validation works, however, when I tried to navigate to another page, it was telling me the web page is not found. Any ideas how to solve this?

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire