Echo content based on the id of the parent element

I’m trynyin to echo the content of an element (zip code) and use it as an input value while diffrentiating (specificity) that of ‘from’, and that of ‘to’. Any ideas on how I can achieve that.

<div id="zone-a">
        <div id="from"> <?php echo um_user('postal_zip_code'); ?> </div>
    <div id="zone-b">
        <div id="to"> <?php echo um_user('postal_zip_code'); ?> </div>
    <form method="post" id="where-to">
        <input type="text" name="from" value="<?php echo um_user('postal_zip_code'); ?>"/>
        <input type="text" name="to"  value="<?php echo um_user('postal_zip_code'); ?>"/>
        <input type="submit" name="submit" value="Submit me!" />

I personally don’t understand what you are trying to accomplish. Can you explain better please?


Would have preferred to edit the question but I don’t know how. Let us assume that the form looks as shown below, how Do I echo the 2 different zip codes into the 2 form fields because they different outputs but the same data-key. Zip codes from zone a and zone b respectively. Thanks

<div id="zone-a">
        <div id="from" data-key="postal_zip_code"> 08091</div>
    <div id="zone-b" datat-key"postal_zip_code"> 08071</div>

Hmm…you have a function called um_user(), which is delivering the data. But, in both calls to the function, you use the same argument 'postal_zip_code'. That will get you the same value or output, or at least it should. If you want a different value from the function, you’ll have to enter a different argument.


Yes. the function writes the prints the zipcode of the different users.

And as long as you feed it the same argument, it will give you the same result back. So you’ll need to think about that.


That is why I’m trying to see if I can tie it to the individual containers and harvest the individual zip-codes

Scott is trying to say you have to add additional parameter to your function.
That will allow you to know which of different zip codes you should return.

Something like this:

<div id="from"> <?php echo um_user('postal_zip_code', 'from'); ?> </div>
<div id="to"> <?php echo um_user('postal_zip_code', 'to'); ?> </div>

and check inside function (sample logic):

function um_user($field, $location){
    if ($field == 'postal_zip_code' && $location == 'from'){
        return 'ZIP_CODE_1';
    if ($field == 'postal_zip_code' && $location == 'to'){
        return 'ZIP_CODE_2';
1 Like

@megazoid I will look at your solution. Thank you so much.

@megazoid I have tried your sample code and kilss the page. I sincerely do not know what I’m doing wrong.

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