Jump to content

Modifying info before submit


Fsoft

Recommended Posts

Hello sir/madem :D,

<form method="POST" action="login.php">
<p align="center">username : <input type="text" name="T1" size="20"></p>
<p align="center">password : <input type="password" name="T2" size="20"></p>
<p align="center"><input type="submit" value="Submit" name="B1"></p>
<p align="center">Username and password can't contain less than 6 chars.</p>
</form>

 

 

Using this code, I made a form which contains username and password field. The only problem is that I don't wan't submit button to submit info to my php file until it verifies that the username and password contains more than 6 chars and (or) is not blank. I can do this verifiction in my php file, but the only problem is for that it will take time as will submit info to php file and then wait for the answer and so on..

 

I can do this with some really simple javascript integrated in same page???

I have 0% knowledge of Javascript please help me with this..

 

Some thing really very simple so that I can learn that easily also..

 

Thanks a lot,

Faisal :)

Link to comment
https://forums.phpfreaks.com/topic/166774-modifying-info-before-submit/
Share on other sites

try:

 


//javascript

<script type="text/javascript">

function check(){

	if(document.getElementybyId('username').value.length<6){

		alert('Username Must Be At Least 6 Characters Long!');

		return false;

		}//end if

	if(document.getElementybyId('password').value.length<6){

		alert('Password Must Be At Least 6 Characters Long!');

		return false;

		}//end if

	document.myform.submit();

	return true;

	}//end function

</script>

//form

<form method="POST" action="login.php" name="myform">
   <p align="center">username : <input type="text" name="T1" id="username" size="20"></p>
   <p align="center">password : <input type="password" name="T2" id="password" size="20"></p>
   <p align="center"><input type="submit" value="Submit" name="B1" onclick="return check();"></p>
   <p align="center">Username and password can't contain less than 6 chars.</p>
</form>

 

lemme know

try:

 


//javascript

<script type="text/javascript">

function check(){

	if(document.getElementybyId('username').value.length<6){

		alert('Username Must Be At Least 6 Characters Long!');

		return false;

		}//end if

	if(document.getElementybyId('password').value.length<6){

		alert('Password Must Be At Least 6 Characters Long!');

		return false;

		}//end if

	document.myform.submit();

	return true;

	}//end function

</script>

//form

<form method="POST" action="login.php" name="myform">
   <p align="center">username : <input type="text" name="T1" id="username" size="20"></p>
   <p align="center">password : <input type="password" name="T2" id="password" size="20"></p>
   <p align="center"><input type="submit" value="Submit" name="B1" onclick="return check();"></p>
   <p align="center">Username and password can't contain less than 6 chars.</p>
</form>

 

lemme know

 

The code seems to be simple and it is.. but it is not working :(

 

Please can you have a look on it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.