Debt Consolidation - Cheat Codes - Find jobs - Wordpress Theme - Find jobs

PDA

View Full Version : Validate Form with JavaScript and send to PHP


piropeator
May 5th 2008, 3:54 pm
I want to validate my form but does not work.
These are my files: form_input.html and form_view.php only to display.
What is the problem?

******* form_input.html
<html>
<title>Input</title>
<script>
function valida_envia(){
//validate name
if (document.fvalida.name.value.length==0){
alert("Write a name")
document.fvalida.name.focus()
return 0;
} else {
// It's OK
alert("The name is OK!");
document.fvalida.submit();
}
}
</script>
</head>

<body>
<form name="fvalida" onsubmit="return valida_envia();" method="POST" action="form_view.php">
<table width="383" border="0" bgcolor="#FFFFFF">
<tr>
<th scope="row"><div align="right">Nombre :</div></th>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<th colspan="2" scope="row">
<input type="submit" value="Input"/> </th>
</tr>
</table>
</form>
</body>
</html>

***** form_view.php

<head>
<title>EJEMPLO</title>
</head>

<body>
The name is : <?php echo $_POST['name'] ?>
</body>
</html>

premium_coder
May 5th 2008, 4:17 pm
it's not return 0
it's return false

piropeator
May 6th 2008, 11:11 am
It works. Thank you.
The syntax of Java is well?