Nasi Nasi - 1 year ago 43
Javascript Question

Form does not take in new values


<form action="./Login.php" method="post" onsubmit="return checkInput();">
<table width="300" border="1">
<th> UserName: </th>
<td><input class="box" type="text" value="" name="uname" id="uname"></td>
<th>Password: </td>
<td><input class="box" type="password" value="" name="pword" id="uname"></td>
<input type="hidden" id="infoDis" value=""/>
<input type="submit" value="Log-in" name="login">
<input type="submit" value="Reset" name="reset">


function checkInput()

var v1 = document.getElementsByName("uname");
var v2 = document.getElementsByName("pword");

var uname = v1[0].getAttribute("value");
var pword = v2[0].getAttribute("value");

if (uname == "" || pword == "")
if(uname == "" && pword != "")
alert("Error: Username is Empty. Please Enter Username.");
else if(pword == "" && uname != "")
alert("Error: Password is Empty. Please Enter Password");
alert("Error: Username And Password is Empty. Please Enter Username and Password");

return false;

return true;

Hi guys. I am new to html/js. I having a small issue where when i enter new values into the textbox. It does not being captured by the javascript. In turn, after a few debugging i found that the javascript is always taking the value in the html tag. Hence, even if value is entered in the first try or in the retry phase, the javascript takes the value in the html "" tag. Please Help Thx.


jQuery to the resuce!

Some people love it, and others hate it. I wouldn't rely on it as your sole frontend library, but if you need to do simple DOM manipulation/interaction, then jQuery is usually a good solution. Grabbing the data stored from a form element is simple in jQuery.

$(document).ready(function() {
  $('.button').on('click', function() {
    var text = $('#some_element).val();

The API docs have easy examples.