PHP Load Variable in Field

6 replies
How would I populate a field form by clicking on a link?
I am pulling info from a database in to a table with many rows

[PHP]
<?php echo $row["zip"]; ?>
[PHP]

I want a person to be able to click the result and have the result load into another for field

PHP Code:
<input name="zip_pu" type="text" required class="zip_pu" pattern="[0-9 -]{7,20}" size="20" value="<?PHP echo $_SESSION['zip_pu'?>">
I am not sure if _SESSION is the way to go, I just know that I want to attempt doing it without javascript
#field #load #php #variable
  • Profile picture of the author otfromtot
    Maybe something along these lines would work?
    PHP Code:
    <td><a href="<?PHP echo $_SERVER['PHP_SELF']; ?>" onclick="<?php $_POST['zip_pu'] = 'zip' ?>"><?php echo $row["zip"]; ?></a></td>
    {{ DiscussionBoard.errors[8324641].message }}
  • Profile picture of the author otfromtot
    If it's not possible without JS then that's fine, the user can copy/paste or type in the data if they need
    {{ DiscussionBoard.errors[8324692].message }}
  • Profile picture of the author Andrew H
    This would be done with javascript. I am not an expert with JS but this should get you in the right direction. I would do it with some jQuery (ie: be sure to load the jquery library or it won't work)

    http://jsfiddle.net/hkSNB/3/

    Code:
    $('td').click(function() {
       tdval = $(this).html();
       $('#yourinputidhere').val(tdval);
    });
    You are just copying the content from the td tag to the input of your choice. Pretty basic stuff.
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8325098].message }}
  • Profile picture of the author otfromtot
    Gonna give that a try as soon as these updates finish, thank you!
    {{ DiscussionBoard.errors[8325386].message }}
  • Profile picture of the author otfromtot
    I made some changes that work for what I needed, if anyone else is looking for something like this
    http://jsfiddle.net/hkSNB/5/
    {{ DiscussionBoard.errors[8338838].message }}
  • Profile picture of the author otfromtot
    jquery ended up being kind of bulky for something so small. I figured out another way where I wouldn't need to load a whole library.
    Code:
    <td class="zip_hover"><a onclick="document.getElementById('zip_pu').value='<?php echo $row["zip"]; ?>';"><?php echo $row["zip"]; ?></a></td>
    Code:
    <td class="zip_hover"><a onclick="document.getElementById('zip_do').value='<?php echo $row["zip"]; ?>';"><?php echo $row["zip"]; ?></a></td>
    {{ DiscussionBoard.errors[8339253].message }}

Trending Topics