Menu
Hi I am trying to create a multipage php form that will use javascript to validate each page before moving to the next page. I also wants to allow the user to go back to the previous page if they need to make correction. I have tried using javascript but does not turn out the way I want it to be. If anyone can give me some direction or direct me to some sample it will be great.
[CODE]
<script type="text/javascript">
<!--
function moveto(id, current, check)
{
valid = true;
if (check == 1)
{
object = document.getElementById(current);
valid = validate(object);
}
if(valid == true)
{
document.getElementById(current).style.display = "none";
document.getElementById(current).getElementsByTagName("span")[0].innerHTML = "";
document.getElementById(id).style.display = "block";
}
else
{
document.getElementById(current).getElementsByTagName("span")[0].innerHTML = "Warning: form incomplete.";
}
}
function validate(id)
{
input = id.getElementsByTagName("input");
valid = true;
for(i = 0; i < input.length; i++)
{
if(input[i].value == "")
{
valid = false;
}
}
return valid;
}
-->
</script>
[/CODE]
[CODE]
<form action="" method="post" onsubmit="return validate(document.getElementById('form3'));">
<table id="form1" border="0">
<tr>
<td>name</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>surname</td>
<td><input type="text" name="surname" /></td>
</tr>
<tr>
<td colspan="2"><button type="button" onmouseup="moveto('form2','form1',1);">Next -></button></td>
</tr>
<tr>
<td colspan="2"><span></span></td>
</tr>
</table>
<table id="form2" style="display: none;" border="0">
<tr>
<td>username</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>password</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td>repeat password</td>
<td><input type="password" name="repeatPassword" /></td>
</tr>
<tr>
<td><button type="button" onmouseup="moveto('form1','form2',0);"><- Back</button></td>
<td><button type="button" onmouseup="moveto('form3','form2',1);">Next -></button></td>
</tr>
<tr>
<td colspan="2"><span></span></td>
</tr>
</table>
<table id="form3" style="display: none;" border="0">
<tr>
<td>E-mail address</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td><button type="button" onmouseup="moveto('form2','form3',0);"><- Back</button></td>
<td><input type="submit" name="submit" value="submit" /></td>
</tr>
<tr>
<td colspan="2"><span></span></td>
</tr>
</table>
</form>
[/CODE]
Hi I am trying to create a multipage php form that will use javascript to validate each page before moving to the next page. I also wants to allow the user to go back to the previous page if they need to make correction. I have tried using javascript but does not turn out the way I want it to be. If anyone can give me some direction or direct me to some sample it will be great.[/quote]
[code=html]<label for="input">Input description</label><input type="text" name="input"/><br/>[/code]
[CODE]label {float: left; width: 200px; text-align: right}
input {float: left; width: 200px; margin-left: 10px;}
br {clear: left;}[/CODE]
That is the one issue though - requiring JavaScript is a dangerous game to play as you have no idea whether the user will have JS turned on........[/quote]
0.1.9 — BETA 6.1