Hi,
i try to make web page with javascript. It's work, but i make validation and i want start the validation only when radio (changement) is checked.
the page :
<html>
<head>
<title>Paiement</title>
<script type="text/javascript">
function HideShow(controlToHide)
{
if (document.getElementById)
{
// Hide all regions
document.getElementById('txtShow1').style.display = 'none';
document.getElementById('txtShow2').style.display = 'none';
document.getElementById('txtShow1').disabled = 'disabled';
document.getElementById('txtShow2').disabled = 'disabled';
// Display the requested region
document.getElementById
('txtShow' + controlToHide).style.display = 'block';
document.getElementById
('txtShow' + controlToHide).disabled = '';
}
else
{
alert('Un erreur est survenu...');
}
}
</script>
<script language="JavaScript">
function Validation(theForm) {
if (theForm.radio.value == "payer") { return (true); }
if (theForm.adresse_input.value == "") {
alert("l'adresse est obligatoire");
theForm.adresse_input.focus();
return (false);
}
if (theForm.pays.value == "") {
alert("vous devez choisir un pays");
theForm.pays.focus();
return (false);
}
if (theForm.province.value == "") {
alert("vous devez choisir une province");
theForm.pays.focus();
return (false);
}
if (theForm.ville.value == "") {
alert("vous devez entrer une ville");
theForm.ville.focus();
return (false);
}
if (theForm.codepostal.value == "") {
alert("vous devez entrer un code postal");
theForm.ville.focus();
return (false);
}
return (true);
}
</script>
</head>
<body>
<?php
require_once('modules/cart/mysql.php');
require_once('modules/cart/global.php');
require_once('modules/cart/functions.php');
echo showpaie();
?>
<form name="frmTest" id="frmTest" action="site.php?cmd=achat" method="post" onSubmit="return Validation(this)">
<table cellpadding="0" cellspacing="0">
<tr valign="top">
<td colspan="2" bgcolor="#000000"><strong style="color:white">Adresse de l'envoie</strong></td>
</tr>
<tr>
<td valign="top">
<input name="radio" type="radio" value="payer" onclick="HideShow(1)" checked /><br />
</td>
<td>
<?php include("envoie_tableau.php"); ?>
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="submit" value="Payer" id="txtShow1"name="txtShow1" style="display:block;" /><br />
</td>
</tr>
<tr>
<td colspan="2" bgcolor="#000000"><strong style="color:white">Changer l'adresse de reception</strong></td>
</tr>
<tr>
<td valign="top">
<input name="radio" type="radio" value="changement" onclick="HideShow(2)"/><br />
</td>
<td>
<?php include("changement_tableau.php"); ?>
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="submit" value="Changer" id="txtShow2"name="txtShow2" style="display:none;" /><br />
</td>
</tr>
</table>
</form>
</body>
</html>
i try to make web page with javascript. It's work, but i make validation and i want start the validation only when radio (changement) is checked.
the page :
<html>
<head>
<title>Paiement</title>
<script type="text/javascript">
function HideShow(controlToHide)
{
if (document.getElementById)
{
// Hide all regions
document.getElementById('txtShow1').style.display = 'none';
document.getElementById('txtShow2').style.display = 'none';
document.getElementById('txtShow1').disabled = 'disabled';
document.getElementById('txtShow2').disabled = 'disabled';
// Display the requested region
document.getElementById
('txtShow' + controlToHide).style.display = 'block';
document.getElementById
('txtShow' + controlToHide).disabled = '';
}
else
{
alert('Un erreur est survenu...');
}
}
</script>
<script language="JavaScript">
function Validation(theForm) {
if (theForm.radio.value == "payer") { return (true); }
if (theForm.adresse_input.value == "") {
alert("l'adresse est obligatoire");
theForm.adresse_input.focus();
return (false);
}
if (theForm.pays.value == "") {
alert("vous devez choisir un pays");
theForm.pays.focus();
return (false);
}
if (theForm.province.value == "") {
alert("vous devez choisir une province");
theForm.pays.focus();
return (false);
}
if (theForm.ville.value == "") {
alert("vous devez entrer une ville");
theForm.ville.focus();
return (false);
}
if (theForm.codepostal.value == "") {
alert("vous devez entrer un code postal");
theForm.ville.focus();
return (false);
}
return (true);
}
</script>
</head>
<body>
<?php
require_once('modules/cart/mysql.php');
require_once('modules/cart/global.php');
require_once('modules/cart/functions.php');
echo showpaie();
?>
<form name="frmTest" id="frmTest" action="site.php?cmd=achat" method="post" onSubmit="return Validation(this)">
<table cellpadding="0" cellspacing="0">
<tr valign="top">
<td colspan="2" bgcolor="#000000"><strong style="color:white">Adresse de l'envoie</strong></td>
</tr>
<tr>
<td valign="top">
<input name="radio" type="radio" value="payer" onclick="HideShow(1)" checked /><br />
</td>
<td>
<?php include("envoie_tableau.php"); ?>
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="submit" value="Payer" id="txtShow1"name="txtShow1" style="display:block;" /><br />
</td>
</tr>
<tr>
<td colspan="2" bgcolor="#000000"><strong style="color:white">Changer l'adresse de reception</strong></td>
</tr>
<tr>
<td valign="top">
<input name="radio" type="radio" value="changement" onclick="HideShow(2)"/><br />
</td>
<td>
<?php include("changement_tableau.php"); ?>
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="submit" value="Changer" id="txtShow2"name="txtShow2" style="display:none;" /><br />
</td>
</tr>
</table>
</form>
</body>
</html>