Pass code via url with / to a java script (php + codeigniter)

0

Hello, I have the following case. I have a part with just a few data from several places, I would like to do something to open a popup to show all the data of that location, so I would need to pass the same id to the url to make the select. Method where I am

foreach ($dadosLocais as $row) {
  $marker = array();
  $marker['position'] = $row->latitude . ',' . $row->longitude;
  $marker['title'] = $row->nome_nascente;
  $dadosUsuario = $this->Usuario_model->getUsuario()->row();
  $marker['infowindow_content'] = '<h2>' . $row->nome_nascente . '</h2>' . 'Descrição: '
  . $row->descricao_nascente . '</br>' . 'Latitude: ' . $row->latitude
  . '</br>' . 'Longitude: ' . $row->longitude
  . '</br>' . 'Usuário que Cadastrou: ' . $dadosUsuario->nome
  .'</br>' . 'Imagem: ' . '<a href="javascript:abrir(500,200)"> Visualizar Imagem</a>'; }

Now my java script is:

    <script languague="javascript">
  function abrir(largura, altura){ window.open('<?= site_url('Nascente/verImagem') ?>','popup','width='+largura+',height='+altura+',scrolling=auto,top=0,left=0') }
</script>

The popup is opening correctly, I just do not know how to pass the local id that is in the forearch to the java script.

    
asked by anonymous 17.11.2016 / 20:00

1 answer

0

I suppose it's going to be something like this. I assumed that $row->ID_LOCAL is in $row , see if that's it. And I changed the order of the parameters by first passing the ID to the popup function, and then largura, altura . If you prefer otherwise, simply change the order.

foreach ($dadosLocais as $row) {
  $marker = array();
  $marker['position'] = $row->latitude . ',' . $row->longitude;
  $marker['title'] = $row->nome_nascente;
  $dadosUsuario = $this->Usuario_model->getUsuario()->row();
  $marker['infowindow_content'] = '<h2>' . $row->nome_nascente . '</h2>' . 'Descrição: '
  . $row->descricao_nascente . '</br>' . 'Latitude: ' . $row->latitude
  . '</br>' . 'Longitude: ' . $row->longitude
  . '</br>' . 'Usuário que Cadastrou: ' . $dadosUsuario->nome
  .'</br>' . 'Imagem: ' . '<a href="javascript:abrir(' . $row->ID_LOCAL . ',500,200)"> Visualizar Imagem</a>'; 

}

I do not know the site_url function of your framework, maybe it has the option of already passing querystring parameters. If you have, use this and do not do this concatenation I did below:

<script languague="javascript">
    function abrir(idLocal, largura, altura) { 
        window.open('<?= site_url('Nascente/verImagem') ?>?idLocal=' + idLocal, 'popup', 'width='+largura+',height='+altura+',scrolling=auto,top=0,left=0');
    }
</script>
    
18.11.2016 / 12:07