Jump to content

PHP -- clickable URL in HTML form


PShannon
 Share

Recommended Posts

Here's what I have:

$website = "https://shakingcrab.com/"  (unquoted)

<input type="url" id="website" name="website" value="<?php echo "<a href='$website'>Website</a>"; ?> ">

This is what the HTML interpreter sees at execution:

<input type="url" id="website" name="website" value="'https://shakingcrab.com/'>Website</a> ">

Thanks . . .

Link to comment
Share on other sites

Because I am vested in:

<input type="url" id="website" name="website" value="<?php echo "<a href='$website'>Website</a>"; ?> ">

That's just one line of code from that form. There's a bunch of data in the form.

Can you help me without suggesting other ways to accomplish this task?

Here's how the Edge browser sees the statement at execution:

<input type="url" id="website" name="website" value="'http://www.barracudatavern.com/'>Website</a> ">

I know I'm close. Any ideas?

I appreciate your input . . .

Link to comment
Share on other sites

<input type="url" id="homepage" name="homepage" value="https://shakingcrab.com/">&nbsp;&nbsp;<input type="button" onclick="triggerlink()" value="go to url">

This is on the right track, but I do not have the value of the target. The value of the target is in a variable, $website.

How does the <input> statement change, given that?

You can see what I am trying to do here: http://www.database39.com/page.php?id=13

(cursor down, below image)

I appreciate you responding. I've been struggling with this for some time . . .

Link to comment
Share on other sites

Use a valid url in input value, it will break if contains the exta apostrophe at beginning and the '</a>', if you copy to address bar and after hitting go and it shows an error, obviously its not valid. Once that is sorted the clicking of added button 'go to url, a function will retrieve the now valid url then redirect to it

 you need to change

var x = document.getElementById("homepage");

to

var x = document.getElementById("website");

Link to comment
Share on other sites

		<input type="url" id="website" name="website" value="https://www.marielofficial.com/">
		<br>
&nbsp;&nbsp;<input type="button" onclick="triggerlink()" value="go to url">
<br>
<script>
function triggerlink(){
var x = document.getElementById("website");

window.location.href=x.value;
}
    </script>

 

Link to comment
Share on other sites

This works! You're a bloody genius! I have been chasing this for weeks. Thank you!

I could use some help cleaning it up a bit.

If you look at the resulting webpage --  http://www.database39.com/page.php?id=17 -- the code produces two rows.

The first row contains https://www.110grill.com/

The second, "action," row contains the legend "Website"

Can the first row be made to "go away?"

Again, I am very grateful.

Edited by PShannon
I have eleven thumbs.
Link to comment
Share on other sites

Forgive my omission. I should have identified the source up front. My bad!

The target URL is stored in a MySQL database as a VARCHAR field in the "bars" table.

The target "bar" is selected via a series of drop-downs -- also sourced from MySQL tables -- that answer the questions:

What neighborhood do you want?
 Do you want a bar or a club/hotel/restaurant bar?
Select from list of bars/clubs/hotels/restaurants in "neighborhood."

Here's a page that shows a "selected" bar and demonstrates the application (cursor down to below image).

http://www.database39.com/page.php?id=519

Again, I am extremely grateful for your consult. I can live with what you have provided, but if it can be polished that last bit by ridding the "URL/link" row above the "action" tab, that would be superb.

 

Link to comment
Share on other sites

Then why not just add the url to a type hidden input, if not supposed to be edited, you could then just add the url to an anchor link with url in href attribute and innerHTML of that anchor link with target attribute value of '_blank', this requires no javascipt as everything required is dynamically added by database.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...