Display unique information according to the value in the form field (email domain)

I've developed an innovative ajax signup form that integrates jQuery and CSS3.

The unique feature of this form is its multi-step process. In the first step, users are required to enter their email address and password.

What sets this form apart is its ability to customize the next step based on the domain of the email address provided. I have identified a specific domain for which I want to display specialized content:

  • Special Option 1

For all other domains such as Gmail, Live, Hotmail, etc., the form should display general options, with the special domain's content hidden. Here are some examples of general options:

  • General Option 1
  • General Option 2
  • General Option 3

I attempted to implement the following code, but unfortunately, it does not seem to be functioning correctly. Despite confirming that my element references are accurate, the code fails to trigger:

var idx = emailaddress.lastIndexOf('@');
if (idx > -1 && emailaddress.slice(idx) === 'premiumcars.co.uk') 
{ function swap(special, general) {
document.getElementById(special).style.display = 'block';
document.getElementById(general).style.display = 'none';
}}

The idea behind this implementation was to segregate the general content within a generic div element and the special content within a designated div element. By utilizing a JavaScript function to identify the domain initially and then switch between elements, the desired result could be achieved.

Answer №1

locate the position of the "@" symbol in the email address
if (idx > -1 && emailaddress.slice(idx) === 'premiumcars.co.uk'){
    display the special element
    hide the general element
}

Instead of creating a function, perform the actions directly within the if statement.

UPDATE: Check out this fiddle for an example of what you want to achieve: http://jsfiddle.net/81r0qenv/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be the reason for the jQuery not displaying JSON data in the console log?

When I put this code into a file named test.html: <html> <head> <title>Test</title> </head> <body> <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script> <script type="text/javascript"& ...

What is the best way to ensure the default style is applied when validating?

input { background: white; color: white; } input:in-range { background: green; color: white; } input:out-of-range { background: red; color: white; } <h3> CSS range validation </h3> Enter your age <input type="number" min="1" max= ...

Ben Kamens has developed a new feature in jQuery Menu Aim where the sub menu will not reappear once it

While exploring Ben Kemens’ jquery-menu-aim, I came across a demonstration on codepen. The code on codepen allows smooth transition from the main menu to the sub menu, but if you move away completely, the submenu remains visible and doesn't disappe ...

PHP failing to send emails from my website

My website has a contact form, but the form data is being appended to the URL and the JSON is not being sent to the PHP mail handler. Below you can find my code for the form. HTML <form novalidate="novalidate" style="width:60%;margin-left:auto;margin- ...

Disabling padding on TwitterTweetEmbed component in React Twitter Embed

Having an issue with Material UI and React Twitter Embed, unable to remove top and bottom margins. Here's the code snippet causing concern: const styles = theme => ({ listItem: { padding: '0px', }, tweetSize: { margin: 0, ...

Incorporating HTML into the Ajax Response

I recently encountered a strange issue with a service that returns an HTML page as the AJAX response. This page contains a form that is automatically triggered by scripts within the page, resulting in a POST request being sent when the page is rendered. My ...

Animations are failing to run within a Bootstrap card when using Vue rendering

I have utilized Bootstrap cards to display pricing information in my project. I implemented a collapse feature for half of the card when the screen size is equal to mobile width. While using vanilla Bootstrap, the animation worked seamlessly with the col ...

Tips for shifting div background image while the push menu is in use

Looking for a Solution: I'm trying to figure out how to adjust my background image within a div when the push menu is active. Here's the CSS I'm currently using: .webcam-bg { background-attachment: fixed; background-image: url("../ ...

Unveiling the hidden secrets of HTML code through scraping

Looking to extract data from the cadastral records in Poland available at . Specifically, I am interested in retrieving information from the element tagged with id 'gfi_0'. The challenge is that this element is not immediately accessible; it only ...

What is the best way to ensure that all the responses to questions in HTML yield a singular outcome?

Can you help me figure out how to link all the answers to questions or user preferences to one ultimate result? I love how Craigslist guides users through their preferences to lead them to one specific outcome. For example, how can I connect these two ques ...

"Efficiently transferring a large file using AJAX and sending it via POST to a

I am facing a challenge with a small script that I am developing. The script is designed to download relatively large files (around 15Mb each) from one domain using AJAX, and then upload/post them to another domain also through AJAX. Downloading the files ...

What is the best way to make a panel width adjust automatically to fit the screen width?

I have developed a React/Material UI application that includes a Portal which showcases a Panel and a Widget. Main App: Show Portal and Set Background Color to Blue export default function App() { return ( <div style={{ backgroundC ...

The window.load() function seems to be malfunctioning as the event is not being triggered. There are no error

I'm struggling with getting the window.load() event to trigger on this specific website. The issue arose last night and despite there being no visible js or php errors, pinpointing the root cause has proven to be quite challenging. In syrp.home.main ...

Achieving a responsive card layout in Reactjs with Bootstrap by displaying four cards in a single row

const DisplayCategory = () => { const history = useHistory(); useEffect(() => { axios.get('http://localhost:8080/products', { headers: { Authorization: "Bearer " + localStorage.getItem("token&q ...

The functionality of Responsive CSS seems to be inconsistent, as it only works partially

Hey everyone, I'm struggling with my responsive CSS code. It seems to be working fine with max-width: 321px but not when I try max-width: 500px. I'm trying to figure out what I'm doing wrong and would really appreciate some help. /*/Mobile ...

Transmit information from JavaScript to a servlet and receive a response in return

I'm new to using ajax and JavaScript. Currently, I have a simple jsp page containing HTML and an accompanying JavaScript file with all my functions defined. One of these functions sends JSON data to a servlet and now I need assistance in receiving th ...

What causes errors in my AJAX request based on the particular file extension?

Utilizing JavaScript and jQuery, I have a function that loads data using $.get(url, function(response){ /* ... */});. The data is retrieved from a text file and handled within the response function of the JavaScript. Recently, I encountered an issue on my ...

php Stristr() function behaving unexpectedly

I recently came across this code on a coding website and made some modifications to it. However, I'm facing an issue with the stristr() function not behaving as expected. For instance, when I input "E", the output displays "Eva" five times, and when I ...

"Utilizing the include method in Rails 4 to serialize multiple variables within the to_json

When utilizing :include in json-response with to_json, I can achieve associations like this: def stats @orders = Order.all respond_to do |format| format.json { render :json => @orders.to_json(:include => :review) } end end Although it fun ...

Place items at the lower part of the container rather than the top

My <ul> has a fixed height and I want the <li> elements inside it to stack at the bottom instead of the top. I attempted using vertical-align: bottom on the <ul>, but that didn't have any effect. The <li> content may overflow ...