Firmeza Firmeza - 5 months ago 8
Javascript Question

javascript, PHP - If input field is not empty, require field

i want to make

input id='pass2' required
if
input id='pass1
value.lenght != null.

<form action="perfil.php" method="post">
<table width="100%" border="0">
<tr>
<td width="10" height="10"></td>
<td colspan=2><p align=justify></p></td>
<td width="4"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td align="left"><font color=#ff0000 id="atencao" size="2em"></font></td>
<td width="4"></td>
</tr>
<tr>
<td></td>
<td align="left">Password:</td>
<td align="left"><input AUTOCOMPLETE=OFF type=password value="" id="password" name="password" style="WIDTH:140px;" maxlength="254" required></td>
</tr>
<tr>
<td></td>
<td align="left">New Password :</td>
<td align="left"><input AUTOCOMPLETE=OFF type=password value="" id="pass1" name="pass1" style="WIDTH:140px;" maxlength="254"></td>
<td></td>
</tr>
<tr>
<td></td>
<td align="left">
Confirm Password :</td>

<td align="left"><input AUTOCOMPLETE=OFF type="password" value="" id="pass2" name="pass2" style="WIDTH:140px;" maxlength="254" onkeyup="checkPass(); return false;"></td>
<span id="confirmarMessagem"></span>
<td></td>


I want to require
pass2
if
pass1
value.lenght is not null on submit or when the field starts gettings input != null.

Answer

This help you :

<script>
  var pass1 = document.getElementById("pass1");
  var pass2 = document.getElementById("pass2");
  pass2.oninput = function(){
         if((pass2.value).length > 0)
             pass1.required = true;
            }  
</script>
Comments