Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

257
Visualizações
Is there way to insert variable in string? (html)

I have not learend any other program language and I started learning html today, I am making program that show random place on google map google map link is this and https://www.google.co.kr/maps/@36.3904052,127.331469,18.09z I wnat to give link like (https://www.google.co.kr/maps/@latitude,longitude,18.09z) this

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>random palce</title>
</head>
<body style="background-color:#FAD0C9;">
    <div style="text-align:center">
        <strong>
            <p style="font-size: 70px; color:#6E6E6D">click the button</p>
        </strong>
        <script>
            var random1 = (Math.floor(Math.random() * (381601797 - 341601796)) + 341601796)/10000000;
            document.write( '<p>' + random1 + '</p>' );
            var random2 = (Math.floor(Math.random() * (1289677998 - 1262365489)) + 1262365489)/10000000;
            document.write( '<p>' + random2 + '</p>' );
         </script>
    <button onclick="location.href='https://www.google.co.kr/maps/'
    " style="width: 350px; height: 150px; font-size: 40px; background-color:#D64161; color:#364b44; border:none; ">random place</button>
    </div>
</body>

this is code I made I want to edit <button onclick="location.href='https://www.google.co.kr/maps/' this part to show link like (https://www.google.co.kr/maps/@latitude,longitude,18.09z)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Firstly, the onclick event is Javascript, not html.

Then, you could use Template literals to insert variable in a string or an url. Also, I would not suggest you to write long Javascript code in onclick. Use addEventListener in script instead.

Template literals are literals delimited with backticks (`), allowing embedded expressions called substitutions.

*I don't really know what the request url format for google map should look like, but directly write coordinates seems to be wrong. You have to figure it out by yourself.

var random1 = (Math.floor(Math.random() * (381601797 - 341601796)) + 341601796) / 10000000;
document.write('<p>' + random1 + '</p>');
var random2 = (Math.floor(Math.random() * (1289677998 - 1262365489)) + 1262365489) / 10000000;
document.write('<p>' + random2 + '</p>');
document.querySelector('button').addEventListener('click', function() {
  location.href = `https://www.google.co.kr/maps/${random1+random2}`

})
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>random palce</title>
</head>

<body style="background-color:#FAD0C9;">
  <div style="text-align:center">
    <strong>
            <p style="font-size: 70px; color:#6E6E6D">click the button</p>
        </strong>

    <button style="width: 350px; height: 150px; font-size: 40px; background-color:#D64161; color:#364b44; border:none; ">random place</button>
  </div>
</body>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda