How to pass a PHP variable that is inside an "a" tag to be used inside a Modal?

Asked

Viewed 1,405 times

0

Hello, I’m new in PHP and I came across a problem: How to pass a PHP variable ($id) that is inside an "a" tag into a Modal?

Here is the code:

<?php
require '../SisCellCenter/autoloader.php';
use VisaoJR\Cellcenter\ClassPHP\Products;
$products = new Products();
?>

<div class="content">
    <div class="new-arrivals-w3agile">
        <div class="container">
            <!-- <h2 class="tittle">Destaques</h2> -->
            <?php
                $featuredProducts = $products->viewFeatureds();
                $rand_keys = array_rand($featuredProducts, sizeOf($featuredProducts)); //escolhe produtos em destaque aleatoriamente
                $max=0;
                if(sizeOf($featuredProducts)>9){$max = 9;} else{$max = sizeOf($featuredProducts);} //exibe no máximo 9 produtos em destaque
                for ($i=0; $i < $max; $i++) {
                ?>

                <div class="arrivals-grids">
                    <div class="col-md-3 arrival-grid simpleCart_shelfItem">
                        <div class="grid-arr">
                            <div  class="grid-arrival">
                                <figure>
                                    <a class="new-gri" id="featured" data-toggle="modal" data-target="#featuredModal" value="<?php $id = $i; ?>">
                                        <div class="grid-img">
                                            <?php echo '<img  src="images/Produtos/'.$featuredProducts[$rand_keys[$i]]->image.'">'; ?>
                                        </div>
                                        <div class="grid-img">
                                            <?php echo '<img  src="images/Produtos/'.$featuredProducts[$rand_keys[$i]]->image.'">'; ?>
                                        </div>
                                    </a>
                                </figure>
                            </div>
                            <div class="ribben">
                                <p>NEW</p>
                            </div>
                            <div class="ribben1">
                                <p>SALE</p>
                            </div>
                            <div class="women">
                                <h6><center><?php echo $featuredProducts[$rand_keys[$i]]->name; ?></center></h6>
                                <span class="size"><?php echo $featuredProducts[$rand_keys[$i]]->brand; ?></span>
                            </div>
                        </div>
                    </div>
                    <!-- <div class="clearfix"></div> -->
                </div>
            <?php }?>
        </div>
    </div>
</div>
<!--content-->


<!--Modal produtos em destaque-->
<div class="modal fade" id="featuredModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content modal-info">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">
                <div class="news-gr">
                    <div class="col-md-5 new-grid1">
                        <?php echo '<img  src="images/Produtos/'.$featuredProducts[$id]->image.'" class="img-responsive" alt="">'; ?>
                    </div>
                    <div class="col-md-7 new-grid">
                        <h5><?php echo $featuredProducts[$id]->name; ?></h5>
                        <h6><?php echo $featuredProducts[$id]->brand; ?></h6>
                        <span><?php echo $featuredProducts[$id]->description; ?></span>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>

From now on, I thank anyone who can help me!

  • You have to use javascritp to solve this, not php.

  • And the <a> tag does not have the value attribute.

  • Because @Yurepereira, I couldn’t think of anything to solve this. Let’s say I’m pretty new in this area

  • Which variable you want to pass ?

  • Take a look at this answer and see if you can help: https://answall.com/questions/58958/passar-vari%C3%A1vel-php-para-javascript

  • What is the variable? $id? Where in the modal do you want to use it? See, Information is as important as code, try to put as much information and clearly so that people can help you. Hug!

  • Yes, it is the $id variable, because with it I can access the product information. or so I if I can I would like to pass this here: $featuredProducts[$rand_keys[$i]], which is the product with all fields

  • I have also used it this way: https://answall.com/questions/129807/enviar-um-valor-para-o-modal

  • @Leo3102, but that variable she’s in a loop, you’ll want as many as you can?

  • Ah ta... I know... pera ae that I will formulate the answer

Show 5 more comments

3 answers

1

How to pass values of PHP to the Javascript and vice versa?

What cannot be ignored in the marriage of Javascript with PHP is that the two are running at different ends. The scripts of Javascript with its variables are in the browser, loaded along with the HTML, and the scripts PHP will have performed their tasks on the other side of WEB, on the server.

The only way of communication between them are the texts (html, javascript…) transiting through the protocol HTTP. It seems a paradox once you find PHP, HTML and Javascript in the same file index.php (for example). However, as stated earlier, each one, PHP and Javascript acts in a different environment. For example:

Let’s assume the file teste.php with the content below:

<html>
   <body>
  <?php echo “Um Hello World !”; ?>
     </body>
</html>
<script type=”text/javascript”>
  alert(“Outro Hello World!”);
</script>

The part that is colored in gray, is static purely text in the form of tags HTML. The line in red corresponds to a program in PHP to write "Hello World!" which will be performed by PHP on the server, and only the result will be delivered to the Browser as follows:

<html>
  <body>
   Um Hello World!
  </body>
</html>
<script type=”text/javascript”>
  alert(“Outro Hello World!”);
</script>

Finally, the colored line in blue also does not suffer modifications between server and browser. However the browser will interpret it as a command to display a small Window with the phrase “Hello World” and a OK button.

So far you can see where everything is happening.

Taking advantage of this apparent meeting, you can build the text of a text Javascript there on the server filling the value of a variable Javascript using PHP:

<html>
  <body>
  <?php echo “Um Hello World!”;
  $nome_individuo = “Cicrano de Mattos Pinto”;
  ?>
  </body>
</html>
<script type=”text/javascript”>
  var nome_individuo_1 = “Fulano”;
  var nome_individuo_2 = “<?php echo $nome_individuo; ?>“;
  alert(nome_individuo_1 + ”  ” + nome_individuo_2);
</script>

As expected, the browser will receive the following:

<html>
  <body>
   Um Hello World!
  </body>
</html>
<script type=”text/javascript”>
  var nome_individuo_1 = “Fulano”;
  var nome_individuo_2 = “Cicrano de Mattos Pinto”;
  alert(nome_individuo_1 + ”  ” + nome_individuo_2);
</script>

And to transfer the value of a variable PHP into a file “.js” ?

So... it’s not possible to make one <? echo… ?> inside a file “.js”, because usually this only works inside a .php. file but it is perfectly possible a <? echo… ?> inside a file “.php” page (index.php por exemplo…) . Let us take into account that this page will also upload files “.js”. For this just create variables (Javascript) global (which may be of the Array), which can be called "environment variables". As they will allow the transit of environmental information HTML+PHP for the scope of the archive Javascript.

<script>
//para não criar muitas variáveis dispersas, é interessante criar um array de variáveis 
var VARS_AMBIENTE = new Array();
//em nosso exemplo vamos preencher a variável de ambiente “caminho_servidor”
// a qual terá seu conteúdo fornecido por um echo PHP
VARS_AMBIENTE[‘caminho_servidor’] = <? echo $caminho_server; ?>;
</script>

Noting that when the HTML + PHP page is loaded into the browser, the above code will be seen as:

<script>
var VARS_AMBIENTE = new Array();
VARS_AMBIENTE[‘caminho_servidor’] = “algum valor fornecido pelo echo do PHP lá no servidor…”;
</script>

For the PHP you will already have done your job on the server when the page is loaded in the browser. And then the code of the script that is in the middle of the HTML will come from the server with the previously filled variable.

Continuing the page index.php… now just load the script that should have some reference to VARS_AMBIENTE[‘caminho_servidor’] to receive the value contained in this variable:

<script src=“meuscript.js”></script>

Ready! Any code contained within meuscript.js which refers to VARS_AMBIENTE[‘caminho_servidor’] will have access to the server path.

And the other way around?

Already from javascript to PHP, as each one will be interpreted at a different end of the web (Javascript - client / PHP - server), the only way to send data is still through traffic through the network. At this time a "magic" tag can help:

<form …>

<input type=“hidden” id=“dados” name=“dados_enviar” value=“” />

</form>

<script>

//aqui a input hidden de id=”dados” recebe um valor dinâmicamente
//via código Javascript:

//cria um objeto de referência à tag input hidden
var objetoDados = document.getElementById(“dados”);
//altera o atributo value desta tag
objetoDados.value = “dados que vão para o servidor”;
</script>

When this data is "submited", it can be acquired on the server through a script PHP capture them via post for example:

<?

echo $_POST[ ‘dados_enviar‘];

?>

Tip: If you copy code to test, rewrite the double quotes in the text editor you are using.

For the WORDPRESS places more aesthetic quotes that are not valid characters in the Engines Javascript and PHP.

Source: https://ahaprogramando.wordpress.com/

0

To redeem the values you used in a loop Therefore, you should save them in a data set called array. =)

Then it would look like this:

<?php 

    ... (codigo anterior) ...

    //declare o array antes do for
    $dados = array();

    $featuredProducts = $products->viewFeatureds();
    $rand_keys = array_rand($featuredProducts, sizeOf($featuredProducts)); //escolhe produtos em destaque aleatoriamente
    $max=0;
    if(sizeOf($featuredProducts)>9){$max = 9;} else{$max = sizeOf($featuredProducts);} //exibe no máximo 9 produtos em destaque
    for ($i=0; $i < $max; $i++) {

    $id = $i;
    $dados[] = $featuredProducts[$rand_keys[$i]]; // salva a variável ou então o id
    // $dados[] = $id; // aqui você usa o id se quiser

    ... (restante) ...

?>

Then just create another loop and rescue this data. So:

 <?php
for($i = 0; $i < count($dados); $i++){

?>
<!--Modal produtos em destaque-->
<div class="modal fade" id="featuredModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content modal-info">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">
                <div class="news-gr">
                    <div class="col-md-5 new-grid1">
                        <?php echo '<img  src="images/Produtos/'.$dados[$i]->image.'" class="img-responsive" alt="">'; ?>
                    </div>
                    <div class="col-md-7 new-grid">
                        <h5><?php echo $dados[$i]->name; ?></h5>
                        <h6><?php echo $dados[$i]->brand; ?></h6>
                        <span><?php echo $dados[$i]->description; ?></span>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>

<?php } ?>

I didn’t do the tests, so it may be that something is wrong. But the logic is this.

  • Thanks for the tip, I used this way to use the $data array.

0

I managed to solve in a very grotesque way using Java Script, follows the modified code:

If someone knows a way to compress this code I appreciate and also make clicking on the image feel like clicking on the input, because the way it is is displaying the value=<?php echo $i;?>.

I thank @otaciojb for the explanation that helped a lot in understanding the subject Client/Server and other colleagues who were willing to help.

(Note: Everything is inside the same file!)

<?php
require '../SisCellCenter/autoloader.php';
use VisaoJR\Cellcenter\ClassPHP\Products;
$products = new Products();
$featuredProducts = $products->viewFeatureds();
$dados = array();
?>

<div class="content">
    <div class="new-arrivals-w3agile">
        <div class="container">
            <h2 class="tittle">Destaques</h2>
            <?php
                $rand_keys = array_rand($featuredProducts, sizeOf($featuredProducts)); //escolhe produtos em destaque aleatoriamente
                $max=0;
                if(sizeOf($featuredProducts)>9){$max = 9;} else{$max = sizeOf($featuredProducts);} //exibe no máximo 9 produtos em destaque
                for ($i=0; $i < $max; $i++) {
                // foreach ($featuredProducts as $fpValue):  //ainda não funciona pois os casos são estabelecidos manualmente no <script>!
            ?>
                <div class="arrivals-grids">
                    <div class="col-md-3 arrival-grid simpleCart_shelfItem">
                        <div class="grid-arr">
                            <div  class="grid-arrival">
                                <figure>
                                    <a href="#" class="new-gri" id="featured" data-toggle="modal" data-target="#featuredModal">
                                        <div class="grid-img">
                                            <?php
                                                $dados[] = $i; // salva o id para uso no Java Script
                                                echo '<img  src="images/Produtos/'.$featuredProducts[$rand_keys[$i]]->image.'">';
                                            ?>
                                        </div>
                                        <div class="grid-img">
                                            <?php echo '<img  src="images/Produtos/'.$featuredProducts[$rand_keys[$i]]->image.'">';?>
                                        </div>
                                        <input type="submit" value="<?php echo $i;?>">
                                    </a>
                                </figure>
                            </div>
                            <div class="ribben">
                                <p>NEW</p>
                            </div>
                            <div class="ribben1">
                                <p>SALE</p>
                            </div>
                            <div class="women">
                                <h6><center><?php echo $featuredProducts[$rand_keys[$i]]->name; ?></center></h6>
                                <span class="size"><?php echo $featuredProducts[$rand_keys[$i]]->brand; ?></span>
                            </div>
                        </div>
                    </div>
                </div>
            <?php }
            // endforeach;
            ?>
        </div>
    </div>
</div>







<div class="modal fade" id="featuredModal" tabindex="-1" role="dialog">';?>
    <div class="modal-dialog" role="document">
        <div class="modal-content modal-info">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">
                <div id='leo' class="news-gr">
                    <script type="text/javascript">
                    $(function(){
                        $("input").click(function(){
                            var valor = $(this).val();
                            if(valor == "<?php echo $rand_keys[0]?>"){
                                featuredClicked="<div class='col-md-5 new-grid1'>"+
                                        "<img  src='images/Produtos/<?php echo $featuredProducts[$rand_keys[0]]->image; ?>' class='img-responsive' alt=''>"+
                                        "</div>"+
                                        "<div class='col-md-7 new-grid'>"+
                                        "<h5>"+"<?php echo $featuredProducts[$rand_keys[0]]->name; ?>"+"</h5>"+
                                        "<h6>"+"<?php echo $featuredProducts[$rand_keys[0]]->brand; ?>"+"</h6>"+
                                        "<span>"+"<?php echo $featuredProducts[$rand_keys[0]]->description; ?>"+"</span>"+
                                        "<div class='color-quality'>"+
                                        "<div class='color-quality-left'>"+
                                        "<h6>Cores:</h6>"+
                                        "olors_idcolors do banco de dados= "+"<?php echo $featuredProducts[$rand_keys[0]]->colors_idcolors; ?>"+
                                        "<ul>"+
                                        "<li><a href='#'><span></span>Red</a></li>"+
                                        "<li><a href='#' class='brown'><span></span>Yellow</a></li>"+
                                        "<li><a href='#' class='purple'><span></span>Purple</a></li>"+
                                        "<li><a href='#' class='gray'><span></span>Violet</a></li>"+
                                        "</ul>"+
                                        "</div>"+
                                        "<div class='clearfix'> </div>"+
                                        "</div>"+
                                        "</div>";
                                document.getElementById('leo').innerHTML=featuredClicked;
                            }
                            else if(valor == "<?php echo $rand_keys[1]?>"){
                                featuredClicked="<div class='col-md-5 new-grid1'>"+
                                        "<img  src='images/Produtos/<?php echo $featuredProducts[$rand_keys[1]]->image; ?>' class='img-responsive' alt=''>"+
                                        "</div>"+
                                        "<div class='col-md-7 new-grid'>"+
                                        "<h5>"+"<?php echo $featuredProducts[$rand_keys[1]]->name; ?>"+"</h5>"+
                                        "<h6>"+"<?php echo $featuredProducts[$rand_keys[1]]->brand; ?>"+"</h6>"+
                                        "<span>"+"<?php echo $featuredProducts[$rand_keys[1]]->description; ?>"+"</span>"+
                                        "<div class='color-quality'>"+
                                        "<div class='color-quality-left'>"+
                                        "<h6>Cores:</h6>"+
                                        "olors_idcolors do banco de dados= "+"<?php echo $featuredProducts[$rand_keys[1]]->colors_idcolors; ?>"+
                                        "<ul>"+
                                        "<li><a href='#'><span></span>Red</a></li>"+
                                        "<li><a href='#' class='brown'><span></span>Yellow</a></li>"+
                                        "<li><a href='#' class='purple'><span></span>Purple</a></li>"+
                                        "<li><a href='#' class='gray'><span></span>Violet</a></li>"+
                                        "</ul>"+
                                        "</div>"+
                                        "<div class='clearfix'> </div>"+
                                        "</div>"+
                                        "</div>";
                                document.getElementById('leo').innerHTML=featuredClicked;
                            }
                            else if(valor == "<?php echo $rand_keys[2]?>"){
                                featuredClicked="<div class='col-md-5 new-grid1'>"+
                                        "<img  src='images/Produtos/<?php echo $featuredProducts[$rand_keys[2]]->image; ?>' class='img-responsive' alt=''>"+
                                        "</div>"+
                                        "<div class='col-md-7 new-grid'>"+
                                        "<h5>"+"<?php echo $featuredProducts[$rand_keys[2]]->name; ?>"+"</h5>"+
                                        "<h6>"+"<?php echo $featuredProducts[$rand_keys[2]]->brand; ?>"+"</h6>"+
                                        "<span>"+"<?php echo $featuredProducts[$rand_keys[2]]->description; ?>"+"</span>"+
                                        "<div class='color-quality'>"+
                                        "<div class='color-quality-left'>"+
                                        "<h6>Cores:</h6>"+
                                        "olors_idcolors do banco de dados= "+"<?php echo $featuredProducts[$rand_keys[2]]->colors_idcolors; ?>"+
                                        "<ul>"+
                                        "<li><a href='#'><span></span>Red</a></li>"+
                                        "<li><a href='#' class='brown'><span></span>Yellow</a></li>"+
                                        "<li><a href='#' class='purple'><span></span>Purple</a></li>"+
                                        "<li><a href='#' class='gray'><span></span>Violet</a></li>"+
                                        "</ul>"+
                                        "</div>"+
                                        "<div class='clearfix'> </div>"+
                                        "</div>"+
                                        "</div>";
                                document.getElementById('leo').innerHTML=featuredClicked;
                            }
                            else if(valor == "<?php echo $rand_keys[3]?>"){
                                featuredClicked="<div class='col-md-5 new-grid1'>"+
                                        "<img  src='images/Produtos/<?php echo $featuredProducts[$rand_keys[3]]->image; ?>' class='img-responsive' alt=''>"+
                                        "</div>"+
                                        "<div class='col-md-7 new-grid'>"+
                                        "<h5>"+"<?php echo $featuredProducts[$rand_keys[3]]->name; ?>"+"</h5>"+
                                        "<h6>"+"<?php echo $featuredProducts[$rand_keys[3]]->brand; ?>"+"</h6>"+
                                        "<span>"+"<?php echo $featuredProducts[$rand_keys[3]]->description; ?>"+"</span>"+
                                        "<div class='color-quality'>"+
                                        "<div class='color-quality-left'>"+
                                        "<h6>Cores:</h6>"+
                                        "olors_idcolors do banco de dados= "+"<?php echo $featuredProducts[$rand_keys[3]]->colors_idcolors; ?>"+
                                        "<ul>"+
                                        "<li><a href='#'><span></span>Red</a></li>"+
                                        "<li><a href='#' class='brown'><span></span>Yellow</a></li>"+
                                        "<li><a href='#' class='purple'><span></span>Purple</a></li>"+
                                        "<li><a href='#' class='gray'><span></span>Violet</a></li>"+
                                        "</ul>"+
                                        "</div>"+
                                        "<div class='clearfix'> </div>"+
                                        "</div>"+
                                        "</div>";
                                document.getElementById('leo').innerHTML=featuredClicked;
                            }
                            else if(valor == "<?php echo $rand_keys[4]?>"){
                                featuredClicked="<div class='col-md-5 new-grid1'>"+
                                        "<img  src='images/Produtos/<?php echo $featuredProducts[$rand_keys[4]]->image; ?>' class='img-responsive' alt=''>"+
                                        "</div>"+
                                        "<div class='col-md-7 new-grid'>"+
                                        "<h5>"+"<?php echo $featuredProducts[$rand_keys[4]]->name; ?>"+"</h5>"+
                                        "<h6>"+"<?php echo $featuredProducts[$rand_keys[4]]->brand; ?>"+"</h6>"+
                                        "<span>"+"<?php echo $featuredProducts[$rand_keys[4]]->description; ?>"+"</span>"+
                                        "<div class='color-quality'>"+
                                        "<div class='color-quality-left'>"+
                                        "<h6>Cores:</h6>"+
                                        "olors_idcolors do banco de dados= "+"<?php echo $featuredProducts[$rand_keys[4]]->colors_idcolors; ?>"+
                                        "<ul>"+
                                        "<li><a href='#'><span></span>Red</a></li>"+
                                        "<li><a href='#' class='brown'><span></span>Yellow</a></li>"+
                                        "<li><a href='#' class='purple'><span></span>Purple</a></li>"+
                                        "<li><a href='#' class='gray'><span></span>Violet</a></li>"+
                                        "</ul>"+
                                        "</div>"+
                                        "<div class='clearfix'> </div>"+
                                        "</div>"+
                                        "</div>";
                                document.getElementById('leo').innerHTML=featuredClicked;
                            }
                            else if(valor == "<?php echo $rand_keys[5]?>"){
                                featuredClicked="<div class='col-md-5 new-grid1'>"+
                                        "<img  src='images/Produtos/<?php echo $featuredProducts[$rand_keys[5]]->image; ?>' class='img-responsive' alt=''>"+
                                        "</div>"+
                                        "<div class='col-md-7 new-grid'>"+
                                        "<h5>"+"<?php echo $featuredProducts[$rand_keys[5]]->name; ?>"+"</h5>"+
                                        "<h6>"+"<?php echo $featuredProducts[$rand_keys[5]]->brand; ?>"+"</h6>"+
                                        "<span>"+"<?php echo $featuredProducts[$rand_keys[5]]->description; ?>"+"</span>"+
                                        "<div class='color-quality'>"+
                                        "<div class='color-quality-left'>"+
                                        "<h6>Cores:</h6>"+
                                        "olors_idcolors do banco de dados= "+"<?php echo $featuredProducts[$rand_keys[5]]->colors_idcolors; ?>"+
                                        "<ul>"+
                                        "<li><a href='#'><span></span>Red</a></li>"+
                                        "<li><a href='#' class='brown'><span></span>Yellow</a></li>"+
                                        "<li><a href='#' class='purple'><span></span>Purple</a></li>"+
                                        "<li><a href='#' class='gray'><span></span>Violet</a></li>"+
                                        "</ul>"+
                                        "</div>"+
                                        "<div class='clearfix'> </div>"+
                                        "</div>"+
                                        "</div>";
                                document.getElementById('leo').innerHTML=featuredClicked;
                            }
                            else if(valor == "<?php echo $rand_keys[6]?>"){
                                featuredClicked="<div class='col-md-5 new-grid1'>"+
                                        "<img  src='images/Produtos/<?php echo $featuredProducts[$rand_keys[6]]->image; ?>' class='img-responsive' alt=''>"+
                                        "</div>"+
                                        "<div class='col-md-7 new-grid'>"+
                                        "<h5>"+"<?php echo $featuredProducts[$rand_keys[6]]->name; ?>"+"</h5>"+
                                        "<h6>"+"<?php echo $featuredProducts[$rand_keys[6]]->brand; ?>"+"</h6>"+
                                        "<span>"+"<?php echo $featuredProducts[$rand_keys[6]]->description; ?>"+"</span>"+
                                        "<div class='color-quality'>"+
                                        "<div class='color-quality-left'>"+
                                        "<h6>Cores:</h6>"+
                                        "olors_idcolors do banco de dados= "+"<?php echo $featuredProducts[$rand_keys[6]]->colors_idcolors; ?>"+
                                        "<ul>"+
                                        "<li><a href='#'><span></span>Red</a></li>"+
                                        "<li><a href='#' class='brown'><span></span>Yellow</a></li>"+
                                        "<li><a href='#' class='purple'><span></span>Purple</a></li>"+
                                        "<li><a href='#' class='gray'><span></span>Violet</a></li>"+
                                        "</ul>"+
                                        "</div>"+
                                        "<div class='clearfix'> </div>"+
                                        "</div>"+
                                        "</div>";
                                document.getElementById('leo').innerHTML=featuredClicked;
                            }
                            else if(valor == "<?php echo $rand_keys[7]?>"){
                                featuredClicked="<div class='col-md-5 new-grid1'>"+
                                        "<img  src='images/Produtos/<?php echo $featuredProducts[$rand_keys[7]]->image; ?>' class='img-responsive' alt=''>"+
                                        "</div>"+
                                        "<div class='col-md-7 new-grid'>"+
                                        "<h5>"+"<?php echo $featuredProducts[$rand_keys[7]]->name; ?>"+"</h5>"+
                                        "<h6>"+"<?php echo $featuredProducts[$rand_keys[7]]->brand; ?>"+"</h6>"+
                                        "<span>"+"<?php echo $featuredProducts[$rand_keys[7]]->description; ?>"+"</span>"+
                                        "<div class='color-quality'>"+
                                        "<div class='color-quality-left'>"+
                                        "<h6>Cores:</h6>"+
                                        "olors_idcolors do banco de dados= "+"<?php echo $featuredProducts[$rand_keys[7]]->colors_idcolors; ?>"+
                                        "<ul>"+
                                        "<li><a href='#'><span></span>Red</a></li>"+
                                        "<li><a href='#' class='brown'><span></span>Yellow</a></li>"+
                                        "<li><a href='#' class='purple'><span></span>Purple</a></li>"+
                                        "<li><a href='#' class='gray'><span></span>Violet</a></li>"+
                                        "</ul>"+
                                        "</div>"+
                                        "<div class='clearfix'> </div>"+
                                        "</div>"+
                                        "</div>";
                                document.getElementById('leo').innerHTML=featuredClicked;
                            }
                            else if(valor == "<?php echo $rand_keys[8]?>"){
                                featuredClicked="<div class='col-md-5 new-grid1'>"+
                                        "<img  src='images/Produtos/<?php echo $featuredProducts[$rand_keys[8]]->image; ?>' class='img-responsive' alt=''>"+
                                        "</div>"+
                                        "<div class='col-md-7 new-grid'>"+
                                        "<h5>"+"<?php echo $featuredProducts[$rand_keys[8]]->name; ?>"+"</h5>"+
                                        "<h6>"+"<?php echo $featuredProducts[$rand_keys[8]]->brand; ?>"+"</h6>"+
                                        "<span>"+"<?php echo $featuredProducts[$rand_keys[8]]->description; ?>"+"</span>"+
                                        "<div class='color-quality'>"+
                                        "<div class='color-quality-left'>"+
                                        "<h6>Cores:</h6>"+
                                        "olors_idcolors do banco de dados= "+"<?php echo $featuredProducts[$rand_keys[8]]->colors_idcolors; ?>"+
                                        "<ul>"+
                                        "<li><a href='#'><span></span>Red</a></li>"+
                                        "<li><a href='#' class='brown'><span></span>Yellow</a></li>"+
                                        "<li><a href='#' class='purple'><span></span>Purple</a></li>"+
                                        "<li><a href='#' class='gray'><span></span>Violet</a></li>"+
                                        "</ul>"+
                                        "</div>"+
                                        "<div class='clearfix'> </div>"+
                                        "</div>"+
                                        "</div>";
                                document.getElementById('leo').innerHTML=featuredClicked;
                            }
                            else {
                                alert("Botão Salvar e Sair");
                            }
                        });

                    });
                    </script>

                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>

Browser other questions tagged

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