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

Exploring the revolutionary combination of Struts 1.3 and Ajax

I'm currently learning about the use of AJAX in a Struts application. I came across some code on the internet that I tried to implement, but I encountered an error stating: `javax.servlet.jsp.JspException: Cannot find bean under name org.apache.strut ...

Issue with Bootstrap 3 dropdown not receiving updates

My goal is to dynamically populate a bootstrap 3 dropdown menu from a MySQL database. Everything works perfectly the first time I load the data. However, when I add more rows to the database, they do not automatically show up in the dropdown. Only after ...

How to efficiently handle callbacks with Angular Services for asynchronous HttpRequests?

I'm struggling with understanding how to correctly implement callback methods for ajax calls in Angular. In my Angular app, I want to display the testUser object only after the ajax call has successfully completed. Here is an example of my ng control ...

html form submission error - please refresh

After submitting a form on my page, I keep encountering an error every time I try to refresh the page. I've attempted several solutions that I came across online, but none of them have resolved the issue as I continue to face this error on different ...

XMLHttp request experiencing mixed content issues

Struggling with obtaining OAuth Tokens from a POST request through the Bungie API using javascript and XMLHttpRequest. Despite both my website and the API endpoint being secure (https), every post request I send returns a Mixed Content page error. I'v ...

Validating decimals in a text field with either JavaScript or jQuery

I need to implement text field validation on the keyup event. The text field should only accept money type decimals such as: (12.23) (.23) (0.26) (5.09) (6.00) If any incorrect value is entered, it should revert back to the previous value and remove the ...

Newbie inquiries regarding the process of migrating a CRUD application to PhalconPHP

I have recently delved into using PhalconPHP 1.3.1 for an application related to my master's thesis. While it is still a work in progress, I am currently focusing on implementing CRUD functionality and refining the user interface. This endeavor marks ...

What is the best way to incorporate JSON into my WordPress loop?

I'm looking to optimize my WordPress loop by retrieving JSON data instead of XML. Currently, I have a working solution but it's quite slow: <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> <?php $title = $post- ...

Trouble detecting click event in jQuery after triggering radio button in HTML

Encountering a peculiar jQuery issue where triggering a click on a radio button does not fire completely and is ignored by an on click function, while a similar call to the jQuery trigger method is successfully captured. In the below jQuery snippet, a < ...

Tips for organizing CSS styles into common and unique statements

Is there a way to apply the same background style but different font styles to two elements without duplicating the style statement in the header part? ...

Overflowing HTML Table Spills Over into Neighboring Div

Is there a way to make the data in a table that spans across multiple pages overflow into a separate div on the initial page without using JavaScript since I am generating it as a PDF? See the images below for reference. Current layout: https://i.stack.im ...

Is there a way to verify the presence of a specific sequence of words within a string using php

I need help with a jquery-ajax quiz that relies on php for validation. One particular question is about identifying the three main characters of a story, but the user may enter them in different sequences like char1 char2 char3    &nb ...

Struggling to display a PHP success message using AJAX

So I have this code where I am trying to create a form in PHP and send a message. The message is being submitted successfully, but I am facing an issue when it comes to displaying a success message. The page submits the data but does not show any output. H ...

TypeScript code runs smoothly on local environment, however encounters issues when deployed to production

<div> <div style="text-align:center"> <button class="btnClass">{{ submitButtonCaption }}</button> <button type="button" style="margin-left:15px;" class="cancelButton" (click)="clearSearch()"> {{ clearButtonCapt ...

invoking a PHP function within a JavaScript script

In my collection of essential functions, there is one that I am particularly interested in: //the functions file //........ function user_exists($username){ $username = sanitize($username); $query = mysql_query("SELECT COUNT('user_id') F ...

Arrow indicating the correct direction to expand or collapse all items with a single click

I have successfully implemented the "expand/collapse all" function, but I am facing an issue with the arrow direction. The arrows are not pointing in the correct direction as desired. Since I am unsure how to fix this problem, I have left it empty in my co ...

The functionality of the jQuery click event is not functioning properly

I encountered a strange issue where the code below works perfectly fine when directly pasted into the browser (chrome console). However, it does not work when executed from my source file. <script type="text/javascript" > $(".test").click( ...

Various Issues Regarding Jquery Libraries

Here's a question on my mind... Currently, in my main file index.php, I have imported jquery 2.0.3 like this: <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> The issue arises bec ...

What is the best way to structure Vue.js components for optimal organization?

Imagine having an index page called index.vue consisting of various components like this: index.vue <template> <div> <component-1 /> <section class="section-1"> <div class="container section-container"> <com ...

Surprising Results when Using getBoundingClientRect()

Check out this code on CodePen In my current project, I'm attempting to position the footer div at the bottom of the page in such a way that it aligns with the maximum value of the bottom coordinates of both the menu and content divs (Math.max(menu, ...