Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

HTML & CSS Is there a way to mask an URL input as text?

I am not sure if this belonged in the CSS or JavaScript section.

I am building a CMS application, and I am stuck at creating input fields for buttons.
The user is allowed to enter a link using an URL-type input field, but when I follow the example from https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/url I am only able to output the entire address for the link, which of course is not exactly pretty.
I much rather have a line that says "Click me" and store the url inside that, but how do I accomplish this through input fields? Is there some way to "mask" it?

For example, if I am manually creating a link, I would simply write:

Code:
<a href="url address">Click here</a>

But keep in mind that this is an application that is based on user-inputs. I cannot expect the user to go in and manually create a button and a link inside the HTML file.
So how do I do it with the code below?

Code:
<input id="myURL" name="myURL" type="url">
 
You would need some Javascript that listens for changes to the "myURL" input box and then injects whatever the value of "myURL" is inside of the href attribute of your link.

What is the context of making the button, ie when a user is editing the button what happens? Is this placing a button on the page, or is this more something that auto-generates the appropriate HTML and places it in a text box, say on an "edit page" sort of screen?
 
You would need some Javascript that listens for changes to the "myURL" input box and then injects whatever the value of "myURL" is inside of the href attribute of your link.

What is the context of making the button, ie when a user is editing the button what happens? Is this placing a button on the page, or is this more something that auto-generates the appropriate HTML and places it in a text box, say on an "edit page" sort of screen?
It is a form that the user can fill out, which includes uploading an image, adding a title and adding a description. These things will then be sent to a database and then shown on a webpage, where the user can either delete or edit the content they just made. But I also want to allow the user to link to something if they wish to.

Lets say the user made a card. The card contains a picture, a title and some text. Normally cards have a "Read more" or "Click here" button.
So I wanted to add an extra input field where the user has the following options:

"Choose a title for the link"
"Enter the URL for the link"

I was hoping it would not be too complicated, because I realized I will need to use this method if I want the user to add or edit stuff on a navbar.
Basically my application allows the user to add, change or delete all content on the page.
 
Could you just have two fields in your database, one for the URL and one for the button text, then when you build the button out after the save just use the button text field from the database?
 
Without JS you can only make a checkbox which you hide and a label with click here.
After that you have to show the input field via CSS and there the user can enter the URL.

But I think that would be much easier to realize with js.
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom