Send the values of the form variables as arguments

I am trying to integrate a webform (shown below) with a function that passes form variables. Once the user clicks submit, I want the username and password to be passed into a website login function:

   $.ajax( { 
            url: "http://microsubs.risk.net/microsub.php",
            method: 'GET',
            success: function (data) {
                if (data == 1) {$('#rdm-below-header').append('<div id=\"modal\" class=\"modalStyle\">' +

                        '<div>' +

                        '<button type=\"button\" id=\"close\" class=\"close\" data-dismiss=\"modal\" aria-label=\"close\"><span aria-hidden=\"true\">&times;</span></button><br>' +

                          '<div id=\"titleText\" style=\" text-align:center; font-size: 24px; margin-top: 15px;\">Fill in your details for 24hr access to Risk.net</div><br>' +


                         '<form id=\"microsubs_form\"  style=\"text-align:center; clear:both\" >' +

                            '<input type=\"text\" id=\"ms_firstName\" name=\"ms_firstName\" required placeholder=\"First Name\" style=\"float:left;\" >'  +

                            '<input type=\"text\" id=\"ms_lastName\" name=\"ms_lastName\" required style=\"float:left; margin-left:20px;\" placeholder=\"Last Name\">' +

                            '<input type=\"email\" id=\"ms_email\" name=\"ms_email\" required placeholder=\"Corporate Email address\" pattern=\"^.*(\*barclays|\*barcap).*$\" oninvalid=\"this.setCustomValidity(\'Please enter your corporate email\')\" style=\"float:left; margin-top: 10px;\">' +

                            '<input type=\"password\" id=\"ms_password\" name=\"ms_password\" required style=\"clear:right; margin-top: 10px; margin-left: 20px;\" placeholder=\"Password\" pattern=\".{6,}\">' +

                            '<input class=\"cls_redirect\" id=\"redirect_url\" name=\"redirect_url\" type=\"hidden\" value=\"http://www.risk-responsive.nginx.incbase.net/\">' +



                            '<input type=\"submit\" id=\"submit-form\"  class=\"btn.login\" name=\"submit\" style=\"alignment-adjust:central; margin-top:30px; clear:right;\" ><br>' +

                        '</form>' +



                         '<div style=\"text-align:center; clear: both; font-size: 16px; margin-top: 5px; \"><br>'  +

                          'If you already have a subscription, <a href=\"login\">sign in here.</a>' +



                         '</div>' +

                     '</div>' +

                    '</div>');
                }
                  console.log(data);
                $('#submit-form').on('click', function(){
                    formSubmit();
                })


             },

             error: function(error) {
                 console.log(error);
             }

        } );


// Function to handle form submission

function formSubmit(){
  $("#microsubs_form").submit(function(event){

 var request;

//
var userName = ms_email;
var userPwd = ms_password;

    // Abort any pending request
    if (request) {
        request.abort();
    }
    // set up some local variables
    var $form = $(this);

    // Let's select and cache all the fields
    var $inputs = $form.find("input, select, button, textarea");

    // Serialize the data in the form
    var serializedData = $form.serialize();


    // Disabled form elements will not be serialized.
    $inputs.prop("disabled", true);

    // Fire off the request to /form.php
  request = $.ajax({
        url: "http://microsubs.risk.net/ms_form_handler.php",
        type: "POST",
        data: serializedData,
        success: function(data){
             console.log(data);
             $("#rdm-below-header").hide();

            siteLogin(userName, userPwd, 'http://www.risk-responsive.nginx.incbase.net/')
        },
        error: function(error) {
                 console.log(error);
             },
    });

    // Prevent default posting of form
    event.preventDefault();
});

In the Ajax call above, notice the **siteLogin(username here, password here, 'http://www.risk-responsive.nginx.incbase.net/')** syntax under success.

The goal is to pass the username and password entered by the user in the form to this function. Although my attempt with the lines below did not work:

 var userName = ms_email;
  var userPwd = ms_password;

If you can offer any help or suggestions, it would be greatly appreciated. Thank you!

Answer №1

To properly include them, follow these steps:

let username = email_input.value;
let password = password_input.value;

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

Is it possible to modify a variable within the readline function?

Can anyone help me figure out how to update the variable x within this function? const readline = require('readline'); const r1 = readline.createInterface({ input: process.stdin, terminal: false }); let x = 1; r1.on('line', fu ...

Adding a new row to a table is causing issues with jQuery

var info = [{ "pin": "015-08-0011-000-01", "arp": "015-08-0011-000-01", "tin": "342-432-423-000", "firstname": "John", "middlename": "James", "lastname": "Jones", "suffix": "", "qtr": "1st ...

Scrolling using JavaScript's 'smooth scrolling' feature is currently disabled

Background of the Issue: I am in the process of creating a one-page website using Twitter Bootstrap 3 within an ASP.NET MVC project. The Challenge: My current challenge involves implementing 'smooth scrolling' functionality that scrolls to the ...

Scope binding is successful, but accessing the array is only possible after adding an Alert() function

Within my Angular controller, I'm utilizing the SharePoint JavaScript Object Model to fetch data from the Taxonomy (term store). Due to SharePoint's JSOM not being a conventional Angular function that can be easily understood by the scope, I util ...

Dealing with CORS, IIS7, and PHP - Overcoming the Access-Control-Allow-Origin obstacle

I am attempting to enable another local host (such as javascript.dev) to make a xhr request to this particular host, which operates on an IIS7 server. When I perform a curl -I command, the headers I receive are as follows: HTTP/1.1 200 OK Content-Length: ...

Converting Ajax to JSON with Jquery offline and Manifest for enhanced offline web applications

Looking to create an offline web application, I'm in the process of transitioning from Ajax to JSON using JQuery offline. Here is the initial Ajax code: $.ajax({ url: contentpage, data: contentpagedata, cache: false }).done(function( html ) { ...

Issue with MUI DataGridPro failing to sort the email field

I am facing an issue with the sorting functionality in the email field while creating a table using MUI DataGridPro. The sorting works fine for all other fields except for the email field. Adding some random text here to ensure my question is published. Pl ...

CSS: Creating a dynamic layout to center the card on screens of all sizes

My code currently places the profile card in the center of the screen regardless of screen size, but it often appears too small. How can I adjust the positioning of the profile card to almost fill the screen? @import url("https://fonts.googleapis.com/cs ...

The remote form is unable to locate the ID for the associated entity

In my software, there is a relationship where a WorkOrder can have multiple LineItems. I am facing an issue where I have a partial file (/views/line_items/_add_line_item.html.erb) being rendered within the WorkOrder#Show (/views/work_orders/show.html.erb) ...

combine ngClass properties if substitution is true

My directive includes replace: true in the definition. <my-custom-tag> </my-custom-tag> This is the template for the directive: <div data-ng-class="{'class1': condition1, 'class2': condition2}"> </div> When u ...

Exploring the concepts of function referencing and prototypical inheritance in relation to function scopes

Consider the scenario where there are two distinct directives: angular.module('demo').directive('functional', [function (){ var idempotentMethods = ['idempotentMethod', 'otherIdempotentMethod']; return { res ...

Can Express not use await?

Why am I encountering a SyntaxError that says "await is only valid in async function" even though I am using await inside an async function? (async function(){ 'use strict'; const express = require("express"); const bodyParser = ...

jQuery document.ready not triggering on second screen on Android device

Why is jQuery docment.ready not firing on the second screen, but working fine on the first/initial screen? I also have jQuery Mobile included in the html. Could jQuery Mobile be causing document.ready to not work? I've heard that we should use jQuery ...

How to get the total number of rows/records in a JSON store using ExtJS?

My dilemma involves a JSON store that provides data in JSON format. I am currently attempting to determine the number of rows or records in the JSON string. However, when utilizing the store.getCount() function, it consistently returns 0. Strangely, the ...

CSS styling doesn't take effect until the page is reloaded due to the failure of cssText

After generating a new list item, it appears that the CSS styling is not being inherited until the page is reloaded. Even though I have added styling using cssText dynamically, it doesn't seem to be working as expected. I've attempted using cssT ...

Unspecified error encountered in the VUE selection view

I am facing an issue with the undefined value in the select view while attempting to add a new project. Could you suggest a solution? I tried using v-if but it didn't work for me. This is how my code looks: <v-select v-model="pro ...

Converting an HTML table into an Excel spreadsheet

In the process of developing an application that populates a table based on a JSON dataset, I am seeking a way to store the filtered data into an Excel file or even a CSV. The structure includes two script files - app.js and mainController.js (organized fo ...

What methods can I use to minimize the duration of invoking the location.reload() function?

When I'm using window.location.reload() in my onClick() function, it's taking too long to reload. I tried modifying the reload call to window.location.reload(true) to prevent caching, but it's still slow. The issue seems to be with location. ...

Searching for columns should be at the top of an angular datatable, not at the bottom

In my Angular 7 project, I am utilizing the library found at this link. I have followed the example provided, which can be seen here. Everything is working perfectly, except for the position of the search columns. I would like the search columns to appear ...

Encountered an issue with trying to access the 'map' property of an undefined value while using Express and VueJS

Currently, I am in the process of developing a fullstack application utilizing Express, VueJS, and Mongoose. The app functions as a news feed platform. A couple of days ago, I encountered an error which was resolved with the help of your guidance. However, ...