Hello:

I am currently developing DomainPhenom dot com, anyways, when you click the inquire button on the websites for sale page I want it to redirect the user to the contact form but fill in the "domain/website" field automatically on the contact form depending on what site or domain they are inquiring about. How would this be done?

Thanks!

Dani AI

Generated

Short practical notes that build on and and address 's "opens in a new window" issue.

A simple, robust approach is to add the domain to the contact link as a query parameter and let the contact page read it and populate the input. On the contact page use the modern URLSearchParams API to parse location.search and set the field value. See URLSearchParams and remember to URL-encode the domain when building the link with encodeURIComponent (encodeURIComponent).

If you want client-only behavior without showing params in the address bar, set a small value in sessionStorage or localStorage on the listing page, then navigate to the contact page and read+clear it there. sessionStorage is per-tab (good for single-session flows); localStorage persists until removed. See Window.localStorage.

If JavaScript might be disabled or you prefer a server-side route, send the domain as a GET or POST parameter and have the server echo it into the form value with proper escaping (use htmlspecialchars in PHP or equivalent). For example, safely output a GET value into an input using htmlspecialchars (htmlspecialchars (PHP)).

Troubleshooting: the reason your code opened a new window is the use of a window‑open call or returning false from an onclick handler. Remove the window.open call and let the anchor navigate normally (or set location.href) if you want same-window navigation. Always validate and escape any incoming parameter before inserting it into the DOM to avoid XSS.

Recommended Answers

All 4 Replies

You could fill in the text field with JavaScript only if it was hard-coded somewhere what to fill it in as. If you want to pass external variables into the page, you would need to use a server-side language such as PHP.

Yeah for now I am just going to have everything hard coded so I can have a specific variable attached to each domain or website link. How would I set that up? Thanks again.

<a href="contact-us.html" onclick="var w=window.open(this.href,'domain','chrome'); formfill(w.document.getElementById('domain'), 'domain.com'); return false;">domain.com</a>

Alright I got it but it opens in a new window, I just want it to go to the page, how can I edit this to work? Thanks!

Try using javascript to set a cookie with the domain information on the first page. Then, on the page with the form, you can read it out and use the domain info from it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.