Onclick et submit de form

Résolu/Fermé
Christian -  
 reda -
Hy.

J'ai un problème de débutant !!!

Je souhaite utiliser des images perso comme bouton submit d'un formulaire.. En fait plusieur images dans le même formulaire qui renvoi une valeur de variable différente et qui execute l'action submit.

il semble que ce soit un truc du style :

<form name="form1" id="form1" method="post" action="index2.php">

<a href="javascript: OnClick=feuille="VALEUR1"; form1.submit();" border=0><img src="IMAGE1.gif"
width="155" height="15" border="0"></a>

<a href="javascript: OnClick=feuille="VALEUR2"; form1.submit();" border=0><img src="IMAGE2.gif"
width="155" height="15" border="0"></a>

</form>


Bien sur, cela ne marche pas...
Je sais faire ça avec PHP mais il semble qu'il y ai plus simple en JS.

Quelqu'un peut-il dire au bleu que je suis comment il faut faire...

D'avance, merci beaucoup.

3 réponses

Julien
 
Salut !

<form name="form1" method="post" action="index2.php">

<input type="hidden" name="feuille" value="">

<a href="#" onclick="document.forms['form1'].feuille.value='VALEUR1';document.forms['form1'].submit();"><img src="IMAGE1.gif" width="155" height="15" border="0"></a>

<a href="#" onclick="document.forms['form1'].feuille.value='VALEUR2';document.forms['form1'].submit();"><img src="IMAGE1.gif" width="155" height="15" border="0"></a>

</form>

Julien
37
jordyelsenor
 
MErci beaucoup julien.
0
reda
 
thank you so much !
0
Julien
 
<script language="javascript">
function fsubmit(value_p)
{
document.forms['form1'].feuille.value = value_p;
document.forms['form1'].submit();
}
</script>
<form name="form1" method="post" action="index2.php">

<input type="hidden" name="feuille" value="">

<a href="javascript:fsubmit('VALEUR1');">
<img src="IMAGE1.gif" width="155" height="15" border="0">
</a>

<a href="javascript:fsubmit('VALEUR2');">
<img src="IMAGE2.gif" width="155" height="15" border="0">
</a>

</form>
10
Christian
 
MERCI BEAUCOUP !
0
doum
 
Salut Julien.
Ton code:
<script language="javascript"> 
function fsubmit(value_p) 
{ 
document.forms['form1'].feuille.value = value_p; 
document.forms['form1'].submit(); 
} 
</script> 
<form name="form1" method="post" action="index2.php"> 

<input type="hidden" name="feuille" value=""> 

<a href="javascript:fsubmit('VALEUR1');"> 
<img src="IMAGE1.gif" width="155" height="15" border="0"> 
</a> 

<a href="javascript:fsubmit('VALEUR2');"> 
<img src="IMAGE2.gif" width="155" height="15" border="0"> 
</a> 

</form>

Est tres bon
Je l'ai adapter pour 2 variables et ca marche.
 html>
<!-- Date de création: 01/01/2004 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<script language="javascript"> 
function fsubmit(value_p,value_q) 
{
document.forms['form1'].quantite.value = value_q; 
document.forms['form1'].prod_id.value = value_p; 
document.forms['form1'].submit(); 
} 

</script> 
</head>
<body>

<form name="form1" method="post" action="plusmoins.jsp"> 

<input type="hidden" name="prod_id" value=""> 
<input type="hidden" name="quantite" value="">

<a href="javascript:fsubmit('VALEUR1','1');"> 
<img src="images/template/plusmoins.gif" width="14" height="19" border="0" > 
</a> 

<a href="javascript:fsubmit('VALEUR2','2');"> 
<img src="images/template/plusmoins.gif" width="14" height="19" border="0" > 
</a>
 
<a href="javascript:fsubmit('VALEUR3','3');"> 
<img src="images/template/plusmoins.gif" width="14" height="19" border="0" > 
</a> 

<table border="0" summary="">
    <tr bgcolor="#FFFFFF">
					<td align="left"><table>
									   <tr>
										 <td><table>
										       <tr><td><A HREF="produit.htm" style="text-decoration: none; color: blue">COCA - <I>Mon Champ</I></a></td></tr>
											  </table></td></tr></table></td>
						
		            <TD align=center NOWRAP>
						<MAP name=1><AREA shape=RECT coords=0,11,20,22  href="javascript:fsubmit('VALEUR1','1');">
						                  <AREA shape=RECT coords=0,0,20,10 href="javascript:fsubmit('VALEUR2','2');"></MAP>
										  <INPUT class=bkInput2 maxLength=4 size=2 value=2 name=qte_1><IMG height="19" hspace="0" src="images/template/plusmoins.gif" width="14" align="absBottom" useMap="#1" border="0" ></TD>
                    <TD align="RIGHT" nowrap bgcolor="#E5E5E5"><div align="left" style="color: #006699; font-family: Times New Roman; font: bold 14px"> 2.60 € </div><div style="color: #BF6026; font-family: Times New Roman; font:bold  14px">1 705 CFA</div></TD>
 					<td align="center"><a href="#"><input style="FONT-SIZE: 10px; FONT-FAMILY: verdana" type="checkbox" onclick="" ></a></td>
					<td align="center"><input type="image" src="images/template/ok.gif" border="0" width="16" height="16" align="absbottom" alt="Cliquez ici pour mettre à jour une quantité ou supprimer un produit" ></td></tr>	
	  
</table>
</form>
</body>
</html>



Question Comment faire si j'ai plusieurs lignes. Quand je reprend ta logique sur deux lignes c juste les premiers variable qui sont pris en compte .
que faire
Merci
0
silent_gamer Messages postés 26 Date d'inscription   Statut Membre Dernière intervention   11
 
il faut changer le type du bouton de validation :

<input type="submit" value="Valider" />

et cava bien marcher
3