Recover parameter sent to a modal and perform Mysql query

Asked

Viewed 871 times

1

I need to recover parameter sent to a modal bootstrap, perform a query in the database and show result in a text field for the user, what I have is this:

Sending the parameter to the modal

<i class="icon-large  icon-book" onclick="VerComentario()" IdCandidato=<?php echo $IdCandidato; ?>></i>

The call of the modal

     // Chamada da janela modal para ver o Comentário
function VerComentario() {
    $("#VerComentario").modal({
        backdrop: false
    });
    $("#VerComentario .modal-header h3").html("Observação Cadastrada");
    $("#VerComentario").modal("show");
}

In modal I have this SQL

    <?php

    $IdCandidato = $_GET['IdCandidato'];

    require_once('../Connections/conCurriculoCocari.php');
        $query = "SELECT * FROM observacao  WHERE id_candidato = $IdCandidato ";
        $result = mysql_query($query) or die ('Error (' . mysql_errno() . ') ' . mysql_error());
    ?> 

But the parameter is not being sent, I need to receive it, send it to the modal to select and show the result to the user

  • Your question is not clear. The modal is a window that opens, it is not connected to the function of sending data to the server side. Who does this is AJAX. Does it make sense what I wrote? has some code/called ajax?

  • Hello @Sergio, thanks for the comment, I’m trying to do something as explained in this post, but it’s not very clear to me, see: http://stackoverflow.com/questions/11003679/dynamically-load-information-to-twitter-bootstrap-modal

1 answer

1


Whenever you want to store some information in an attribute of <tag> which is not valid HTML you have to use the prefix data-.

Consider the following HTML:

<div id="minha-div" data-mensagem="Olá Mundo!"></div>

You can retrieve information as follows (using jQuery):

alert( $("#minha-div").data("mensagem") );

See on Jsfiddle: http://jsfiddle.net/7J2Ru/

  • Thanks Andrey, this tip helped me a lot, thanks, thanks also to @Sergio, I understood your placement.

Browser other questions tagged

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