Use a DIV content as element variable

I’m trying to use the content of a DIV as PHP variable in an array but it doesn’t work. I have tried a couple of methods but none of them worked. How can I achieve that.

<div id="place">08091</div>
<div id="destination">19977</div>

<?php $destination='08071';?>        

    <?php $destination='19977';?>

    <?php
        // Our parameters
        $params = array(
            'origin'        =>    $place,
            'destination'    => $destination,
            'sensor'        => 'true',
            'units'            => 'imperial'
        );
        
    ?>

Well for starters,

You can use the right name for your variable? :wink:

Would have loved to edit the question but I see no option to do so.

Editing gets locked out after a while. Just make another post in this thread…

Hope the respost explains my intenshions better. 

<div id="whereFrom">08091</div>
<div id="whereTo">19977</div>

<?php $place='content-of-whereFrom-as-the-variable';?>        

    <?php $destination='content-of-whereTo-as-the-variable';?>

    <?php
        // Our parameters
        $params = array(
            'origin'        =>    $place,
            'destination'    => $destination,
            'sensor'        => 'true',
            'units'            => 'imperial'
        );
        
    ?>

Where do the values of the divs come from?

PHP runs on the server side.

If you’re waiting for the user to put things into the div’s, you’ll need to use AJAX to send the data to PHP.

The div’s are populated already with the values. I’m trying to bring their zip codes together and calculate the distance automatically.

but… if you’re writing the div values in, why would you not just write them into where you’re putting your variables? I’m missing something here.

<div id="whereFrom">08091</div> //If I write '08091' here..
<?php $place='content-of-whereFrom-as-the-variable';?> //I just type '08091' here....

The content of the DIV’s are dynamic

… so what’s filling them in? They cant be dynamic and say “08091” in your code file at the same time, because that’s static.

They are called with somelike like

<?php echo um_user('zip_code'); ?>

so…

  <?php
        // Our parameters
        $params = array(
            'origin'        =>    um_user('zipcode'),
            'destination'    => $destination,
            'sensor'        => 'true',
            'units'            => 'imperial'
        );
        
    ?>

The question is how do I refer to dentition div content since they are both rendered with the same um_user(‘zipcode’)

They cant both be using the SAME function with the same input and get different results unless something has changed.

Every user has their own zip-code outputted to their profile. The scenario is whenever I’m looking at my friend’s profile, I get to see the dis from their place to mine. Calculated automatically using the friend’s zip-code and mine.

So what function is being used to fill the destination div?

a plugin function

okay… show me the whole code page of where you’re doing this, and we will point it out for you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.