antoniogonca95
antoniogonca95

Reputation: 57

Clicking on a div and saving its value to use with PHP

I have been having some problems with some code. So I'm developing a website that accesses a mysql database and creates a number of divs accordingly to the number of specialties that are on the database.

    <div id="services_panel">
        <?php foreach ($specialties as $especialidade_id => $especialidade) { ?>
            <div class="service_div" onclick ="highlightLink(this); $('#content_div').show();" value="<?php echo $especialidade_id; ?>"><?php echo $especialidade; ?></div>
        <?php } ?>
    </div>
    <div id="content_div""/>

Now what I wanted to do was set the value of the content div to the value of $especialidade of the div that was clicked, but since javascript runs clientside and php runs server side, I know that I can't do it on onclick()

I'd really hope you guys could help me with this issue

Thanks in advance

Upvotes: 3

Views: 97

Answers (1)

Sean
Sean

Reputation: 12433

Using onclick() inline you could do

onclick ="highlightLink(this); $('#content_div').show().html(this.innerHTML);"

or if you bind it separately using .on() and 'click'

$(function(){
    $('.service_div').on('click',function(){
       $('#content_div').show().html($(this).html()); 
    });
});

Upvotes: 1

Related Questions