Automatically populate login credentials on a webpage using Javascript scripting

Can anyone provide insights on why the input credentials on a webpage cannot be autofilled with this code? Is there a solution to make it functional?

Trying to automate login process using JavaScript:
function Test() {
  var name = document.getElementById("usuario").value;
  var password = document.getElementById("password").value;
  document.forms["formulario"].submit(); //form submission
}
<form id="formulario" name="formulario" method="post" target="_top" action="https://www.allianz.pt/area-privada">
  <input id="usuario" name="_58_login" type="text" value="examplelogin" runat="server" />
  <input id="password" name="_58_password" type="password" value="examplepassword" runat="server" />
  <button onclick="Test()" id="btn">Submit</button>
</form>

Answer №1

Make sure you are assigning values to the input fields before submitting the form.

function SubmitForm() {
  var username = document.getElementById("username");
  var email = document.getElementById("email");

  // Assigning values to the username and email input fields
  username.value = "JohnDoe";
  email.value = "johndoe@example.com";

  document.forms["userForm"].submit(); //Submitting the form
}

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

Retrieve the AJAX response data to be utilized in future operations

It appears that there is a bug in using INNERHTML where my SELECT OPTION tag becomes blank, based on the research I have done. I am trying to figure out how to create a variable containing my OPTION tags for later use, based on the JSON data below, but I a ...

Pass the ID of a dynamic textbox element to a child window upon clicking a link

One of the challenges I'm facing involves a textbox labeled "Branch Code" that links a branch to a corporate card transaction. At times, there is a requirement to split a transaction among multiple branches. To facilitate this process, I am constructi ...

What is another option for toggling in jQuery?

After deprecating the toggle method, I found a new way to toggle div: $("#syndicates_showmore").on("click", function () { if (!clicked) { $('#syndicates').fadeTo('slow', 0.3, function () { $(this).css( ...

What is the proper way to safely escape a JSON string for an object that contains user-generated content?

How can I correctly use the variable s for the value-field of an option-element while escaping user input used for key and value? var key='highway'; var value='track'; var s = JSON.stringfy({ [key]:value }, undefined,''); s ...

Tips for displaying or concealing a specific block by clicking on an element

I have a list-menu called .sidebar-menu and each li within this list has its own unique id. There is also a block called .services-info, containing several blocks with one of them supposed to appear when you click on an item in the .sidebar-menu that corre ...

Avoiding the transfer of values via URL in Node.js

Currently, I'm in the process of developing a login system that involves hashing passwords instead of transmitting them via the URL. The frontend comprises a form through which users input their credentials, which are then compared against the stored ...

Creating a dynamic dropdown menu using JQuery that does not automatically submit the form when a value is

Upon selecting a background color from the dropdown menu, I am generating a dynamic dropdown for text colors. The Text Color dropdown is populated correctly based on the selection of Background Color. Although the functionality works as intended, I encoun ...

I need help in updating my user information using jQuery, JavaScript, AJAX, and the Node.js API

Working with a dynamic table that fetches JSON data from the API (/api/dashboard/v1) using the GET method. There is another API (/api/updateUser/v1:id) available for updating user information using the PUT method. A table has been created with an Edit op ...

Image set as the background on a website

I recently started working with Groovy and Grails, designing my own personal website. I'm looking to set an image (located in the asset folder) as the background for my index.gsp page. How can I achieve this? ...

How come Vue.js is not showing the image I uploaded?

Even though I can successfully print the image URL, I'm facing an issue where the img tag is not displaying it, despite my belief that I've bound it correctly. <html> <head> <title>VueJS Split Demo</title> <script t ...

Using jQuery's click function to manipulate multiple div elements

Currently, I am attempting to use jQuery's click function in order to implement a hover effect on a selected div without having to differentiate between the divs in the JavaScript code. Here is what I have so far: $(document).ready(function(){ $ ...

New to CSS/Ruby - What causes two adjacent buttons to have varying sizes?

The varying sizes of my search and login buttons located beside each other are puzzling me. Could it be due to the fact that the search button is enclosed within a submit_tag argument while the login button is not? If this is indeed the case, how can I mak ...

Is Sending an Object to a Function in the Same Scope Inefficient?

Is there a noticeable delay when passing around an object within the same scope? Let's explore Option 1 and Option 2. In Option 1, we work directly with the object, while in Option 2 we follow better encapsulation practices. However, if we were to sti ...

The expiry date of the cookie remains unchanged

When attempting to create a cookie and specify an expiration date, I am encountering an issue where it remains as "Session". This problem is occurring in Google Chrome. I'm looking for insights on what might be causing this behavior. The code snippe ...

Unable to display image on React page using relative file path from JSON data

Greetings, this is my initial post so please forgive me if I have missed any important information. I'm currently in the process of creating a webpage using react. My goal is to display content on the page by iterating over a relatively straightforwa ...

Issue with setting GeoJSON in jQuery callback using Mapbox`

Using Jquery, I am trying to retrieve geojson points data (which will set markers on a map) from a database. function remm(id){ $.ajax({ type: "POST", url:"geojson2.php", data:{ u_id:id[0], t_id:id[2] }, success: functi ...

Freshly updated, discover how to create an underlined navbar menu item

I'm trying to underline the currently selected menu item in a navbar, but I'm having trouble getting it to work. Here's my code: .navbar-nav .nav-item:focus .nav-link { text-decoration: underline; background-color: yellow; } It&apo ...

Unique rewritten text: "Special case: This is not defined

I am in the process of creating my own custom exception in Node.js to handle errors specific to the environment the server is running in. However, when the error is thrown, it shows as undefined. (function () { 'use strict'; var states = req ...

How can we reduce the size of a JSON object in Typescript before sending it to the client?

Currently, I am faced with a common challenge. I have a database object that is a standard JS object originating from a document database, and my goal is to transmit this object to the client. However, certain fields contain sensitive information that shou ...

Discover the XPath of a post on a Facebook page with the help of HtmlUnit

I am trying to fetch the xpath of a Facebook post using HtmlUnit. To better understand my goal, you can check out these two related questions: Supernatural behaviour with a Facebook page HtmlUnit commenting out lines of Facebook page To replicate my pro ...