Home > database >  How do I get a value from html and post it?
How do I get a value from html and post it?

Time:01-23

im a begginer web developer and i want to make something like that: you login with username end password, then it redirects you to the home page, and says something like this: Hello (username) welcome! but i dont know how to read the value from the input please help

i searched it up but it only showed a search input option

CodePudding user response:

This is too generalized for such a question. Many questions: -Are you using any backend? If so which one (what language? And what kind of database (ie SQL etc.))?

To store data you need a backend or at least use frontend js's localStore (would work if every page is on the same domain and server).

Yet another front-end way would be to pass the information as url-parameters and get them.

But if you really want to build a robust login system of any kind, the best way is to use backend (PHP/node JS/Java/python etc.) and store the data in a database (SQL etc.). And make sure it is secure, but security is too broad of a topic for this question.

CodePudding user response:

Your asked very generalized question, for my assumption there you want to do either one of these

  1. when you login, you want to keep username from input and and redirect the user to home page and show the username on the label like hello abcd
  2. You have an input field with username on home page and want to show the text of the input field into label

so, I will give answer considering the above scenarios, the answer will be considering how I will do things(as I don't know what you are using in backend the answer may vary)

for point 1 I will store the username in a localstorage, sessionstorage or cookie.

let's say I used sessionstorage, the below code will be performed on my login button click

sessionStorage.setItem('quantity',document.getElementById('username').value);

and on my pageLoad of home page I will set the value in my label like below

document.getElementById('lblusername').text = sessionStorage.getItem('quantity');

option 2,

on my home Page I will simply get the value from input field and show it on label

document.getElementById('lblusername').text = document.getElementById('username').value;

let me know if it helped you as I don't know your exact scenario

  • Related