How to access page according to input text field?

Asked

Viewed 160 times

0

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

I thought to use a javascript and take the entered value and change the value of a variable, with this do a series of comparisons with ifs or whiles and when the value is equal to the correct name it goes to page x.

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

NOTE: pages x and y are pages inside the project folder and not internet urls.

  • 1

    Page x or y differ only in src of an image? or there are more differences?

  • then, are different pages, with a different body. but the head, css, javascript or msm.

  • wanted something like if (var = sanduíche) {vai para pagina tal} else if (var = salamandra) {vai para outra página e nessa página mude a src da imagem para o caminho tal} It would be great to record this variable in cache, not in a database. since the msm site will be used by more than one person, and need to operate independently.

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>

<form action="">
  <input type="text" id="envia" placeholder="digite o valor">
  <input type="button" onclick="verificaValor()" value="envia">
</form>
<div id="result">
  
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.