Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Can I get a form field to populate with an ID from another html page?

Featured Replies

Hi. A customer wants a basic online catalogue and a link/button next to each product taking the user to a enquiry form. Is there a way i can bring the product ID to a form field? Like if I gave a certain button the ID PROD154, could i get that to autofill a form field on a different HTML page when the button is clicked? Thanks :)

you would need to use php, send the button as a form to the page, populate the button into a php array then tell the form to grab the php array data.

Another alternative would be to provide the id in a hashtag on the end of the url. So say your product ID was 78, you would link to your enquirees page through a link like http://whatever.com/enquirees#78.

 

Then on your enquirees page, use javascript to input the hashtag into your form field for example:

 

<input type="text" name="product_id" value="<script type="text/javascript">document.write(window.location.hash[1])</script>" />

Another alternative would be to provide the id in a hashtag on the end of the url. So say your product ID was 78, you would link to your enquirees page through a link like http://whatever.com/enquirees#78.

 

Then on your enquirees page, use javascript to input the hashtag into your form field for example:

 

<input type="text" name="product_id" value="<script type="text/javascript">document.write(window.location.hash[1])</script>" />

This is very interesting stuff. Where can I find out more about hash tags? Seems to be a massive thing in Twitter.

That's a different type of hash tag. On Twitter, a "hash tag" is used to define a subject or a group for a twitter post to belong to. I'm sure you can find more about that if you search google for "twitter hash tags".

 

Technically, what I'm talking about probably isn't called a "hash tag", i just named it that. It is basically an extension to the end of an URL that is designed to make the browser 'jump' to an element with that ID. However, you can use it for other things such as in my example.

Thanks for the clarification.

I notice you used hash[1], Is there such a thing as a hash[2] and if so what separator is used.

Thanks again.

TBH, I would look into learning at least the basics of PHP. It is an invaluable skill if you're breaking into the world of web design.

Sorry TopShopper, my previous example was incorrect, it should read as below:

 

document.write(window.location.hash.substr(1))

And as hairlet says, you may wish to look into learning PHP. It would probably be much simpler performing this task using PHP instead of Javascript.

Yeh, I know PHP and ASP methods which would normally use the querystring (?) parameter but this looked like an interesting addition to my repertoire. I will investigate further this hash thing.

Thanks for the feedback.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.