How to access page according to input field?

0

Hello, I have an input field in my HTML, I want to make it depending on the text you type, it goes to page x or y. I also need that depending on, go to a page and on that page change the src of an image to a specific path.

I thought of using a javascript and get the value entered and change the value of a variable, so do a series of comparisons with ifs or whiles and when the value is equal to the correct name it goes to page x. p>

I know there are a number of frameworks out there that would make the process easier, but I'm new to it and I'm trying to take it one step at a time.

NOTE: Pages x and y are pages within the project folder and not web urls.

    
asked by anonymous 06.11.2016 / 05:34

1 answer

0

Simple to do with jQuery.

function verificaValor(){
  var valor = $('#envia').val();
  if (valor == 'salamandra'){
    window.location.href = 'http://google.com/'
  } else if(valor == 'pitanguinha'){
    window.location.href = 'http://facebook.com';
  }
  else{
    $('#result').html('Insira um valor válido');
  }
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formaction="">
  <input type="text" id="envia" placeholder="digite o valor">
  <input type="button" onclick="verificaValor()" value="envia">
</form>
<div id="result">
  
</div>
    
06.11.2016 / 17:13