IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

fonction javascript et onsubmit sur une page


Sujet :

JavaScript

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    86
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 86
    Points : 46
    Points
    46
    Par défaut fonction javascript et onsubmit sur une page
    Bonjour

    Ci joint mon script je precise que je ne connais pas la programmation en Javasript.

    Voilà donc mon PB ci joint le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
     
    <?php  
     
    if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") ) { // enregistrement des données
     
     
    } // fin de l'enregistrement des données
     
     
    ?>
     
    <script type='text/javascript'>
    //<![CDATA[
    var geocoder = null;
     
    function AfficherAdresse(addresse,lon_ad,la_ad,com_ad) {
    	if  (geocoder) {
    		geocoder.getLatLng(
    			addresse,
    			function(point) {
    				if (!point) {
    					alert('Impossible de geolocaliser cette adresse'+addresse+com_ad+cp);
    				} else {
    					MaCarte.addControl(new GMapTypeControl());
    					MaCarte.addControl(new GOverviewMapControl());
    					MaCarte.addControl(new GLargeMapControl());
    					var marker = new GMarker(point, {draggable: true});
    					GEvent.addListener(marker, 'dragstart', function() {
    						MaCarte.closeInfoWindow();
    					});
    					GEvent.addListener(marker, 'dragend', function(point) {
    						AfficheGPS(marker);
    					});
    					MaCarte.addOverlay(marker);
    					AfficheGPS(marker);
    					MaCarte.setCenter(point, 15);
    				}
    			}
    		);
    	}
    }
    //]]>
    </script>
    <html>
    <head>
    <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAD_snjZhIrbGNNRZrIdrTARSOQON08a6Pxfkjf9mWq3Ul" type="text/javascript"></script>
    <meta http-equiv="Content-Language" content="fr,ca">
    <link type="text/css" rel="stylesheet" href="../style.css">
    </head>
    <body onLoad="load() " onUnload="GUnload()" bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <!-- ImageReady Slices (gpsevasion_v3.psd) -->
    <table width="802" height="86" border="0" align="center" cellpadding="0" cellspacing="0" id="Tableau_01">
      <tr> 
        <td width="823" height="32" align="center" valign="top"> <div align="center"> 
            <?php if (!isset($_POST['enregistrer'])){ // affichage fichier ?>
            <form method="post" name="creation_poi" id="creation_poi" action="poi_proposition_visiteur_beta.php" onsubmit="AfficherAdresse(this.ad_ad.value,this.lon_ad.value,this.la_ad.value,what.value); return false">
              <table width="100%" border="0">
                <tr> 
    			  <td width="43%" align="center" valign="top"><div id="EmplacementDeMacarte" style="width: 350px; height: 360px"></div></td>
    			  <td width="57%" height="345" align="center" valign="top"> <table width="100%" align="center">
                      <tr> 
                        <td colspan="3" class="Tableau_titre"><div align="center"><? echo $tx_titre14 ?></div></td>
                      </tr>
                      <tr valign="baseline"> 
                        <td width="22%" align="right" nowrap class="Tableau_corps"><div align="right"><? echo "$tx_form3" ; ?></div></td>
                        <td colspan="2" class="Tableau_corps"> <input name="nom_ad" type="text" class="Boite" value="<? echo $_SESSION['nom_ad'] ?>" size="60"> 
                        </td>
                      </tr>
                      <tr valign="baseline"> 
                        <td height="24" colspan="3" align="right" nowrap class="Tableau_corps"> 
                          <div align="right"> 
                            <table width="102%" border="1" cellspacing="0" bordercolor="#FF0000" class="Tableau_corps">
                              <tr> 
                                <td colspan="4"><div align="center" id="message"></div></td>
                              </tr>
                            </table>
                            <input name="position_lonla" type="submit" class="bouton" value="Localisation (long/lat)"  onClick="what=this" >
                          </div></td>
                      </tr>
                      <tr> 
                        <td colspan="3" class="Tableau_titre"><div align="center"><? echo $tx_titre15 ?></div></td>
                      </tr>
                      <tr valign="baseline"> 
                        <td align="right" nowrap class="Tableau_corps"><div align="right"><? echo "$tx_form4" ; ?></div></td>
                        <td width="55%" class="Tableau_corps"><input name="ad_ad" type="text" class="Boite" value="<? echo $_SESSION['ad_ad'] ?>" size="60"></td>
                        <td width="23%" align="center" valign="middle" class="Tableau_corps"><input name="position_ad" type="submit" class="bouton" value="Localisation (adresse)"  onClick="what=this" ></td>
                      </tr>
                      <tr valign="baseline"> 
                        <td height="22" align="right" nowrap class="Tableau_corps">&nbsp;</td>
                        <td colspan="2" class="Tableau_corps"><input name="enregistrer" type="submit" class="bouton" value="Proposer (adresse)"  ></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <p> 
              </p>
              <p> 
                <input type="hidden" name="MM_insert" value="form1">
                <input type="hidden" name="m" value="1">
              </p>
            </form>
            <p>&nbsp;</p>
            <? } ?>
            <?php if (isset($_POST['enregistrer'])){ // affichage fichier ?>
            <table width="52%" border="0" align="center">
              <tr> 
                <td class="Tableau_titre"><div align="center"><? echo $tx_titre16 ?></div></td>
              </tr>
              <tr> 
                <td height="64" class="Tableau_corps"> <div align="center"> 
                    <p class="right">&nbsp;</p>
                    <p class="right"><a href="../poi_proposition_visiteur.php"><? echo "$tx_form16" ; ?></a></p>
                    <p class="right"><a href="../index.php"><? echo "$tx_form17" ; ?></a></p>
                    <p class="right">&nbsp;</p>
                  </div></td>
              </tr>
              <tr> 
                <td class="Tableau_corps"><div align="center"></div></td>
              </tr>
            </table>
            <p>&nbsp;</p>
            <? } ?>
            <p>&nbsp;</p>
          </div></td>
      </tr>
    </table>
    <!-- End ImageReady Slices -->
    </body>
    </html>
    J’ai une feuille avec une carte google , mon visiteur saisie une adresse ou une longitude et latitude.

    En cliquant sur le bouton « vérifier adresse » ou « vérifier lon/la » il lance la fonction « AfficherAdresse » et positionne cette derniere sur la carte.

    Je pense qu a ce niveau ça marche.

    Une fois l’adresse correctement positionner je souhaite enregistrer dans ma base données les infos en cliquant sur le bouton « Proposer (adresse) » de facon classique en php

    Et la ca ne marche pas je relance la fonction « AfficherAdresse » comme je ne connais pas javascript je dois louper des choses

    Pouvez vous me donner un coup de main pour votre info voir la page de test

    http://www.gps-evasion.com/_rep1/poi...iteur_beta.php

    merci pour votre aide

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Ton bouton
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <input name="enregistrer" type="submit" class="bouton" value="Proposer (adresse)"  >
    soumet ton formulaire, donc comme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <form method="post" name="creation_poi" id="creation_poi" action="poi_proposition_visiteur_beta.php" onsubmit="AfficherAdresse(this.ad_ad.value,this.lon_ad.value,this.la_ad.value,what.value); return false">
    Tu as mis sur l'évèment onsubmit, l'appelle à AfficherAdresse(this.ad_ad.value,this.lon_ad.value,this.la_ad.value,what.value); return false" et que tu retourne FALSE, donc ton formulaire ne fera pas l'action action="poi_proposition_visiteur_beta.php" mais seulemnt que de lancer AfficherAdresse(...)

    Enfin je pense

    Tu peux créer un autre bouton standard qui sur onclick lancera AfficherAdresse(...) et tu enlève le onsubmit du form

    A+

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    86
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 86
    Points : 46
    Points
    46
    Par défaut
    merci je vais tester ton analyse

    peux tu me donner la syntaxe afin d'etre sur

    merci

  4. #4
    Expert éminent sénior

    Homme Profil pro
    Inscrit en
    Janvier 2007
    Messages
    13 474
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2007
    Messages : 13 474
    Points : 36 571
    Points
    36 571
    Par défaut
    Bonjour,
    Citation Envoyé par gpsevasion Voir le message
    peux tu me donner la syntaxe afin d'etre sur
    il suffit d'enlever le "return false" ...

    A+

  5. #5
    Invité
    Invité(e)
    Par défaut
    Bonjour, cela est vrai E.Bzz

    Cependant, la fonction AfficherAdresse (...) devrait être utilisée par les boutons "Localisation" voir image.



    Il faudrait leur mettre un type="button" et un onclick avec l'appel à la fonction et les bons paramètres. Ainsi, dans le form, il pourra être supprimé le onsubmit, le form fera donc son office pour transmettre les paramètres nécessaire au script qui va bien.

    Bon, je peux me tromper

    A+

  6. #6
    Expert éminent sénior

    Homme Profil pro
    Inscrit en
    Janvier 2007
    Messages
    13 474
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2007
    Messages : 13 474
    Points : 36 571
    Points
    36 571
    Par défaut
    Citation Envoyé par jlmag Voir le message
    Cependant, la fonction AfficherAdresse (...) devrait être utilisée par les boutons "Localisation" voir image.
    Je n'ai pas eu le temps de regarder autant en détail

    A+

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    86
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 86
    Points : 46
    Points
    46
    Par défaut
    merci pour votre aide je regarde le script et je vous tiens au courant

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    86
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 86
    Points : 46
    Points
    46
    Par défaut
    merci pour votre aide comme toujours tres efficace

    voila la soluc




    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
     
    <?php  
     
    if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") ) { // enregistrement des données
     
     
    } // fin de l'enregistrement des données
     
     
    ?>
     
    <script type='text/javascript'>
    //<![CDATA[
    var geocoder = null;
     
    function AfficherAdresse(addresse,lon_ad,la_ad,com_ad) {
    	if  (geocoder) {
    		geocoder.getLatLng(
    			addresse,
    			function(point) {
    				if (!point) {
    					alert('Impossible de geolocaliser cette adresse'+addresse+com_ad+cp);
    				} else {
    					MaCarte.addControl(new GMapTypeControl());
    					MaCarte.addControl(new GOverviewMapControl());
    					MaCarte.addControl(new GLargeMapControl());
    					var marker = new GMarker(point, {draggable: true});
    					GEvent.addListener(marker, 'dragstart', function() {
    						MaCarte.closeInfoWindow();
    					});
    					GEvent.addListener(marker, 'dragend', function(point) {
    						AfficheGPS(marker);
    					});
    					MaCarte.addOverlay(marker);
    					AfficheGPS(marker);
    					MaCarte.setCenter(point, 15);
    				}
    			}
    		);
    	}
    }
    //]]>
    </script>
    <html>
    <head>
    <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAD_snjZhIrbGNNRZrIdrTARSOQON08a6Pxfkjf9mWq3Ul" type="text/javascript"></script>
    <meta http-equiv="Content-Language" content="fr,ca">
    <link type="text/css" rel="stylesheet" href="../style.css">
    </head>
    <body onLoad="load() " onUnload="GUnload()" bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <!-- ImageReady Slices (gpsevasion_v3.psd) -->
    <table width="802" height="86" border="0" align="center" cellpadding="0" cellspacing="0" id="Tableau_01">
      <tr> 
        <td width="823" height="32" align="center" valign="top"> <div align="center"> 
            <?php if (!isset($_POST['enregistrer'])){ // affichage fichier ?>
            <form method="post" name="creation_poi" id="creation_poi" action="poi_proposition_visiteur_beta.php" >
              <table width="100%" border="0">
                <tr> 
    			  <td width="43%" align="center" valign="top"><div id="EmplacementDeMacarte" style="width: 350px; height: 360px"></div></td>
    			  <td width="57%" height="345" align="center" valign="top"> <table width="100%" align="center">
                      <tr> 
                        <td colspan="3" class="Tableau_titre"><div align="center"><? echo $tx_titre14 ?></div></td>
                      </tr>
                      <tr valign="baseline"> 
                        <td width="22%" align="right" nowrap class="Tableau_corps"><div align="right"><? echo "$tx_form3" ; ?></div></td>
                        <td colspan="2" class="Tableau_corps"> <input name="nom_ad" type="text" class="Boite" value="<? echo $_SESSION['nom_ad'] ?>" size="60"> 
                        </td>
                      </tr>
                      <tr valign="baseline"> 
                        <td height="24" colspan="3" align="right" nowrap class="Tableau_corps"> 
                          <div align="right"> 
                            <table width="102%" border="1" cellspacing="0" bordercolor="#FF0000" class="Tableau_corps">
                              <tr> 
                                <td colspan="4"><div align="center" id="message"></div></td>
                              </tr>
                            </table>
                          <input name="position_lonla" type="button" class="bouton" value="Localisation (long/lat)"  onclick="AfficherAdresse(document.creation_poi.ad_ad.value,document.creation_poi.lon_ad.value,document.creation_poi.la_ad.value)" >
                          </div></td>
                      </tr>
                      <tr> 
                        <td colspan="3" class="Tableau_titre"><div align="center"><? echo $tx_titre15 ?></div></td>
                      </tr>
                      <tr valign="baseline"> 
                        <td align="right" nowrap class="Tableau_corps"><div align="right"><? echo "$tx_form4" ; ?></div></td>
                        <td width="55%" class="Tableau_corps"><input name="ad_ad" type="text" class="Boite" value="<? echo $_SESSION['ad_ad'] ?>" size="60"></td>
                        <td width="23%" align="center" valign="middle" class="Tableau_corps">
                          <input name="position_ad" type="button" class="bouton" value="Localisation (adresse)"  onclick="AfficherAdresse(document.creation_poi.ad_ad.value,document.creation_poi.lon_ad.value,document.creation_poi.la_ad.value)" >
                      </tr>
                      <tr valign="baseline"> 
                        <td height="22" align="right" nowrap class="Tableau_corps">&nbsp;</td>
                        <td colspan="2" class="Tableau_corps"><input name="enregistrer" type="submit" class="bouton" value="Proposer (adresse)"  ></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <p> 
              </p>
              <p> 
                <input type="hidden" name="MM_insert" value="form1">
                <input type="hidden" name="m" value="1">
              </p>
            </form>
            <p>&nbsp;</p>
            <? } ?>
            <?php if (isset($_POST['enregistrer'])){ // affichage fichier ?>
            <table width="52%" border="0" align="center">
              <tr> 
                <td class="Tableau_titre"><div align="center"><? echo $tx_titre16 ?></div></td>
              </tr>
              <tr> 
                <td height="64" class="Tableau_corps"> <div align="center"> 
                    <p class="right">&nbsp;</p>
                    <p class="right"><a href="../poi_proposition_visiteur.php"><? echo "$tx_form16" ; ?></a></p>
                    <p class="right"><a href="../index.php"><? echo "$tx_form17" ; ?></a></p>
                    <p class="right">&nbsp;</p>
                  </div></td>
              </tr>
              <tr> 
                <td class="Tableau_corps"><div align="center"></div></td>
              </tr>
            </table>
            <p>&nbsp;</p>
            <? } ?>
            <p>&nbsp;</p>
          </div></td>
      </tr>
    </table>
    <!-- End ImageReady Slices -->
    </body>
    </html>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 09/11/2010, 19h31
  2. [DOM] Appeler une fonction javascript se trouvant sur une autre page
    Par monstor dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 04/09/2008, 11h11
  3. [Javascript] rediriger sur une page en javascript
    Par tioseb dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 15/02/2006, 14h55
  4. javascript sur une page creation flash mx
    Par hadjplasma dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 17/08/2005, 12h06
  5. comment rediriger sur une page html en fonction de la langue
    Par pierrot10 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 10/08/2005, 11h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo