I want a program to redirect a person to a site if he clicks the submit button in a form only if the text input is 12345 and redirect to another page of input is 56789 using Javascript
            Asked
            
        
        
            Active
            
        
            Viewed 408 times
        
    -3
            
            
        - 
                    2Welcome to stackoverflow. Please read [How to create a Minimal, Complete, and Verifiable question](http://stackoverflow.com/help/mcve) again and again – caramba Feb 08 '17 at 12:38
3 Answers
0
            You can get some idea from the below code:
function validate() {
 var digits = document.frm.digits1.value;
 if(digits == '12345')
 {
  location.href = 'http://www.google.com';
  
 }
 else if (digits == '56789')
 {
  location.href = 'http://www.yahoo.com';
 }
 else
 {
  alert('digits are wrong');
 }
 
 return false;
 
}<form name="frm" method="post" onsubmit="return validate()" >
<input type="text" name="digits1" id="digits1"  />
<input type="submit" value="submit" />
</form> 
    
    
        Azeez Kallayi
        
- 2,567
- 1
- 15
- 19
0
            
            
        You need to use the code below:
HTML:
<form id="form" action="#">
<input type="text" id="text"/>
<input type="submit" value="Submit">
JavaScript:
document.getElementById("form").onsubmit = function() {myFunction()};
function myFunction() {
    text = document.getElementById("text").value;
    if (text=="12345"){
        alert("Redirecting to: http://www.your.1st.url.com");
        document.location = "http://www.your.1st.url.com";
    } else if (text=="56789"){
        alert("Redirecting to: http://www.your.2nd.url.com");
        document.location = "http://www.your.2nd.url.com";
    }
}
Sources:
 
    
    
        Community
        
- 1
- 1
 
    
    
        Thanasis1101
        
- 1,614
- 4
- 17
- 28
- 
                    You are very welcome. Since it helped you can tick my answer as accepted and give it an upvote. Thank you. – Thanasis1101 Feb 08 '17 at 13:42
0
            
            
        You could use the following idea or similar.
document.getElementById('myform').onsubmit = function() {
    if(document.getElementById('myinput').value == '56789')
        document.getElementById('myform').action = 'anotherpage.html';
};
 
    
    
        ohteam
        
- 1
