-1
Guys I’m trying to change the tag link , which is within one when the user chooses one of the options of . I’m trying to make this change with PHP. But I’ve done several ways and it didn’t work. Can someone suggest me some solution?
<!doctype html>
<html lang="pt-br">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="form-group">
<label for="metrica">Escolha a Métrica Desejada:</label>
<select class="form-control" name="metrica" id="metrica">
<option name="host" value="1">Host</option>
<option name="DG" value="2">Distância Geográfica</option>
<option name="custo"value="3">Custo</option>
</select>
<small class="form-text text-muted">Selecione a métrica do cálculo</small>
<button type="button" class="btn btn-outline-primary">
<?php
//$mt = isset($_GET['metrica']) ? $_GET['metrica']:0;
$ht = isset($_GET['host']) ? $_GET['host']:0;
$dg = isset($_GET['DG'])? $_GET['DG']:0;
$ct = isset($_GET['custo'])? $_GET['custo']:0;
if($ht):?>
<a href='principal.html'>Escolher cidades</a>;
<?php
elseif($dg):
?>
<a href='principal.1.html'>Escolher cidades</a>;
<?php
elseif($ct):
?>
<a href='principal.2.html'>Escolher cidades</a>
<?php
endif;
?>
</button>
<div id="myDiv"></div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous">
</script>
</body>
</html>
Could you give an example? When to select
Host
thehref
must beprincipal.html
and so on? No need to change the text? $off: Why put thea
within thebutton
? It doesn’t seem ideal...– LipESprY
@Lipespry that’s right.when it’s "host" the href of being main.html, if it’s "Demographic distance" it will go main.1.html and if it chooses "cost", it will go to main.2.html.
– Moises Moraes
@Lipespry on the <a> tag is a habit of mine to do so! Maybe a bad habit.
– Moises Moraes
Every nut with his craze (Gambi)! Since the button will not perform any action, the ideal is not to use it. If you want your link to look like a button, make it look like a button!
– LipESprY
Your code is wrong. Besides it being wrong to use <a> inside <button>, you should take the value of select in GET, not the option. You must take the value of
name="metrica"
, which will be the value of the selected option.– Sam
But I do not understand why my if is giving error. I removed the button or no text appears.
– Moises Moraes
@Sam made the change you mentioned, now the text appears, but href keeps the same,'main.html', for everyone.
– Moises Moraes