Jump to content
ajetrumpet

populate textbox after clicking href URL

Recommended Posts

I have this code:

echo "<td><a href = 'https://whatismyipaddress.com/ip-lookup' target = '_blank'>$col</a></td>";

the textbox I want to populate on the page has name attribute "LOOKUPADDRESS".  it has no id attribute.  after clicking on the link, is it possible  to fill the textbox with $col?

Share this post


Link to post
Share on other sites
1 hour ago, ajetrumpet said:

it has no id attribute

Why not?  That's the whole point in having an id attribute, to identify it easily.  Instead of having to use

textarea[name='LOOKUPADDRESS']

you can use

#LOOKUPADDRESS

To get you textarea to populate, though, you'll need to listen for the click of the anchor tag, or modify what happens when it's clicked.

<a href="#nowhere" id="anchor">Click HERE</a>
<textarea id="LOOKUPADDRESS"></textarea>
document.getElementById('anchor').onclick(function(arg){
	arg.preventDefault();
	var t = document.getElementById("LOOKUPADDRESS").innerText = "<?php echo $col; ?>";
});

I haven't tested any of this code, so copy and paste at your own risk.

Share this post


Link to post
Share on other sites

what's the purpose of this:

<a href="#nowhere"

am I supposed to copy that into my code literally?

I tried:

<a href="#nowhere" id="anchor">"https://whatismyipaddress.com/ip/" . $col </a>

but i'm getting an -unexpected "- and -unexpected "<" error in eclipse.

Share this post


Link to post
Share on other sites

i don't think i follow you my friend.  the link i'm trying to specify in the <href is not where i'm being sent, like i said before.

Share this post


Link to post
Share on other sites

What page do you want to link to? So far you have

  • href = 'https://whatismyipaddress.com/ip-lookup'
  • href = 'https://whatismyipaddress.com/ip'

Have you tested them by entering the link addresses in your browser?

Edited by Barand

Share this post


Link to post
Share on other sites

what i want is:  https://whatismyipaddress.com/ip

and then of course $col concatenated on the end.  without $col on the end of the URL, the link takes me to:  https://whatismyipaddress.com/ip-lookup

and yes i've tested them.  what i said above happens the same way in the browser too.  e.g. - without $col on the end of the first link, it redirects to the second link.

Share this post


Link to post
Share on other sites

Then you want

echo "<td><a href='https://whatismyipaddress.com/ip/$col' target='_blank'>$col</a></td>";

 

Share this post


Link to post
Share on other sites

hey wonderful!  thanks!  for a guy desperately in need in petrol, you are certainly knowledgeable enough!

Share this post


Link to post
Share on other sites

here's an example for you

<?php

$link1 = "<a class='LOOKUP' href='http://google.com'  target='_blank'>Site 1</a>";
$link2 = "<a class='LOOKUP' href='http://yahoo.com'  target='_blank'>Site 2</a>";

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    $().ready( function() {
        $(".LOOKUP").click( function(event) {
            event.preventDefault()
            var loc = $(this).attr("href")
            var linktext = $(this).html()
            $("#mytext").append(linktext + "\n")
            window.open(loc, '_blank');
        })
    })
</script
</head>
<body>
    <?=$link1?>
    <br>
    <?=$link2?>
    <br>
    <h3>Visited links</h3>
    <textarea rows="5" cols="35" id="mytext" ></textarea>
</body>
</html>

 

Share this post


Link to post
Share on other sites

is this:

Quote

"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"

this geolocation library that google offers?  it doesn't look like it.  when godaddy failed me on the geolocation extension implementation I google the issue and found some HTML code that uses the free google apis for that purpose.

Share this post


Link to post
Share on other sites

this code is from this page:  https://stackoverflow.com/questions/409999/getting-the-location-from-an-ip-address

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script>
contry_code = google.loader.ClientLocation.address.country_code
city = google.loader.ClientLocation.address.city
region = google.loader.ClientLocation.address.region
</script>

will this work to capture geo data?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.