Bienvenu(e)! Identification Créer un nouveau profil

Recherche avancée

lancer une fonction java sans son bouton

Envoyé par pierrotm777 
lancer une fonction java sans son bouton
lundi 24 mai 2010 19:17:00
Bonjour ,

je suis un petit nouveau.

Je souhaiterais modifier une page html.
Celle-ci est composée d'un input, puis un bouton de validation,
d'un deuxième input , puis d'un autre bouton de validation,
puis d'un troisième bouton pour lancement final.

Chaque bouton est associé à une fonction java enfin je crois.
Je n'ai pas besoin du troisième bouton est voudrais que la fonction 'direction()' soit lancée directement
aprés l'appuie sur le deuxième bouton .

voici le code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[www.w3.org];
<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps Multi-Point Routing for Ride Runner</title>
<script src="[maps.google.com]; type="text/javascript"></script>

</head>
<body onunload="GUnload()">

<table>

<tr>
<td width=700>
<div id="map" style="width: 755px; height: 490px; border:1px solid black"></div>
</td>
<td width=400>
<div id="path" style="width: 400px; height: 490px; overflow:auto; border:1px solid black"></div>
</td>
</tr>
</table>



<div id="start">
Enter the address of the starting point or click the map.
<form onsubmit="showAddress(); return false" action="#">
<input id="search" size="60" type="text" value="" />
<input type="submit" value="Find start address" />
</form>
</div>

<div id="end">
Enter the address of the destination point or click the map.
<form onsubmit="showAddress(); return false" action="#">

<input id="search2" size="60" type="text" value="" />
<input type="submit" value="Find destination address" />
</form>
</div>

<div id="drag">
Drag the markers as required.
<input type="button" value="Get Directions" onclick="directions()" />
</div>

<noscript><b>JavaScript must be enabled in order for you to use Google Maps.</b>
However, it seems JavaScript is either disabled or not supported by your browser.
To view Google Maps, enable JavaScript by changing your browser options, and then
try again.
</noscript>

<script type="text/javascript">
//<![CDATA[

if (GBrowserIsCompatible()) {

var map = new GMap(document.getElementById("map"winking smiley);
map.addControl(new GLargeMapControl3D());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(40,-100),5);
map.enableScrollWheelZoom();

var bounds = new GLatLngBounds();

// ====== Create a Client Geocoder ======
var geo = new GClientGeocoder(new GGeocodeCache());

// ====== Array for decoding the failure codes ======
var reasons=[];
reasons[G_GEO_SUCCESS] = "Success";
reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value.";
reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address.";
reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons.";
reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed.";
reasons[G_GEO_BAD_REQUEST] = "A directions request could not be successfully parsed.";
reasons[G_GEO_MISSING_QUERY] = "No query was specified in the input.";
reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";

// ====== Geocoding ======
function showAddress() {
if (state==0) {
var search = document.getElementById("search"winking smiley.value;
addresses[0] = search;
}
if (state==1) {
var search = document.getElementById("search2"winking smiley.value;
addresses[4] = search;
}
geo.getLatLng(search, function (point)
{
if (point) {
if (state==1) {doEnd(point)}
if (state==0) {doStart(point)}
}
else {
var result=geo.getCache().get(search);
if (result) {
var reason="Code "+result.Status.code;
if (reasons[result.Status.code]) {
reason = reasons[result.Status.code]
}
} else {
var reason = "";
}
alert('Could not find "'+search+ '" ' + reason);
}
}
);
}

function swapMarkers(i) {
map.removeOverlay(gmarkers);
createMarker(path,i,icon2);
}

var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.iconSize=new GSize(24,38);

var icon1 = G_START_ICON;
var icon2 = G_PAUSE_ICON;
var icon3 = G_END_ICON;
var icon4 = new GIcon(baseIcon,"[labs.google.com]winking smiley;
icon4.shadow = "[labs.google.com];;
icon4.iconSize = new GSize(12, 20);
icon4.shadowSize = new GSize(22, 20);
icon4.iconAnchor = new GPoint(6, 20);
icon4.infoWindowAnchor = new GPoint(5, 1);


function createMarker(point,i,icon) {
var marker = new GMarker(point, {draggable:true,icon:icon});
gmarkers=marker;
GEvent.addListener(marker, "dragend", function() {
path = marker.getPoint();
if (!active) {
setTimeout('swapMarkers('+i+')', 1000);
}
active = true;
addresses = "";
});
map.addOverlay(marker);
}


// ===== Array to contain the points of the path =====
var path = [];
var active = [true,false,false,false,true];
var gmarkers = [];
var addresses = [];

// ===== State Driven Processing =====
var state = 0;

function handleState() {
if (state == 0) {
document.getElementById("start"winking smiley.style.display = "block";
document.getElementById("end"winking smiley.style.display = "none";
document.getElementById("drag"winking smiley.style.display = "none";
}
if (state == 1) {
document.getElementById("start"winking smiley.style.display = "none";
document.getElementById("end"winking smiley.style.display = "block";
document.getElementById("drag"winking smiley.style.display = "none";
}
if (state == 2) {
document.getElementById("start"winking smiley.style.display = "none";
document.getElementById("end"winking smiley.style.display = "none";
document.getElementById("drag"winking smiley.style.display = "block";
}
}

handleState();

GEvent.addListener(map, "click", function(overlay,point) {
if (point) {
if (state == 1) { doEnd(point) }
if (state == 0) { doStart(point) }
}
});

function doStart(point) {
createMarker(point,0,icon1);
path[0] = point;
state = 1;
handleState();
}

function doEnd(point) {
createMarker(point,4,icon3);
path[4] = point;
state = 2;
handleState();
for (var i=1; i<4; i++) {
var lat = (path[0].lat()*(4-i) + path[4].lat()*i)/4;
var lng = (path[0].lng()*(4-i) + path[4].lng()*i)/4;
var p = new GLatLng(lat,lng);
createMarker(p,i,icon4);
path = p;
}
bounds.extend(path[0]);
bounds.extend(path[4]);
map.setZoom(map.getBoundsZoomLevel(bounds));
map.setCenter(bounds.getCenter());
}

var gdir=new GDirections(null, document.getElementById("path"winking smiley);

GEvent.addListener(gdir,"error", function() {
var code = gdir.getStatus().code;
var reason="Code "+code;
if (reasons
) {
          reason = "Code "+code +" : "+reasons
        }
        alert("Failed to obtain directions, "+reason);
      });

      var poly;
      GEvent.addListener(gdir, "load", function() {
        if (poly) map.removeOverlay(poly);
        poly = gdir.getPolyline();
        map.addOverlay(poly);
      });


      function directions() {
        if (addresses[0]) {var a = addresses[0] + "@" + path[0].toUrlValue(6)}
          else {var a = path[0].toUrlValue(6)}
        if (addresses[4]) {var b = addresses[4] + "@" + path[4].toUrlValue(6)}
          else {var b = path[4].toUrlValue(6)}
        for (var i=3; i>0; i--) {
          if (active) {
            b = path.toUrlValue(6) +" to: "+b;
          }
        }
        var a = "from: "+a + " to: " + b;
        gdir.load(a, {getPolyline:true});
      }
    }

    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser"winking smiley;
    }

    </script>
  </body>

</html>

je sent bien que cela doit ce passer par là,
    <div id="drag">
       Drag the markers as required.
       <input type="button" value="Get Directions" onclick="directions()" />
    </div>
mais sans savoir comment fire .

Merci pour votre aide.

Nota:
Cette page fonctionne autour de Google Maps.
Les deux input permettent de données une ville , les deux premiers boutons de valider les input et le troisième de calculer le trajet à lister.
Seuls les utilisateurs enregistrés peuvent poster des messages dans ce forum.

Cliquez ici pour vous connecter