ajetrumpet Posted October 15, 2019 Share Posted October 15, 2019 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? Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/ Share on other sites More sharing options...
ajetrumpet Posted October 15, 2019 Author Share Posted October 15, 2019 another option I supposed is to do: echo "<td><a href = 'https://whatismyipaddress.com/ip/' . $col target = '_blank'>$col</a></td>"; i tried this and also tried putting $col in ' ' quotes, but i'm sent to the page: https://whatismyipaddress.com/ip-lookup Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570678 Share on other sites More sharing options...
Zane Posted October 15, 2019 Share Posted October 15, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570679 Share on other sites More sharing options...
ajetrumpet Posted October 15, 2019 Author Share Posted October 15, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570680 Share on other sites More sharing options...
Barand Posted October 15, 2019 Share Posted October 15, 2019 3 hours ago, ajetrumpet said: but i'm sent to the page: https://whatismyipaddress.com/ip-lookup Why would you expect a link to pageXYZ not to send you to pageXYZ? Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570683 Share on other sites More sharing options...
ajetrumpet Posted October 15, 2019 Author Share Posted October 15, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570684 Share on other sites More sharing options...
Barand Posted October 15, 2019 Share Posted October 15, 2019 (edited) 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 October 15, 2019 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570685 Share on other sites More sharing options...
ajetrumpet Posted October 15, 2019 Author Share Posted October 15, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570686 Share on other sites More sharing options...
Barand Posted October 15, 2019 Share Posted October 15, 2019 Then you want echo "<td><a href='https://whatismyipaddress.com/ip/$col' target='_blank'>$col</a></td>"; Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570687 Share on other sites More sharing options...
ajetrumpet Posted October 15, 2019 Author Share Posted October 15, 2019 hey wonderful! thanks! for a guy desperately in need in petrol, you are certainly knowledgeable enough! Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570688 Share on other sites More sharing options...
Barand Posted October 15, 2019 Share Posted October 15, 2019 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> Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570691 Share on other sites More sharing options...
ajetrumpet Posted October 15, 2019 Author Share Posted October 15, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570693 Share on other sites More sharing options...
Barand Posted October 15, 2019 Share Posted October 15, 2019 It's a link to jQuery function library Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570695 Share on other sites More sharing options...
ajetrumpet Posted October 15, 2019 Author Share Posted October 15, 2019 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? Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570703 Share on other sites More sharing options...
ajetrumpet Posted October 15, 2019 Author Share Posted October 15, 2019 FORGET THAT POST. i'm getting my threads confused here. Quote Link to comment https://forums.phpfreaks.com/topic/309374-populate-textbox-after-clicking-href-url/#findComment-1570704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.