Forum Moderators: coopster

Message Too Old, No Replies

Change data on the same page to something else

         

outdoorxtreme1

6:48 pm on Aug 8, 2006 (gmt 0)

10+ Year Member



I'm trying to change data on this line of code using a drop down option box.

map.centerAndZoom(new GPoint(-79.89505, 40.85708), 10);

When the page opens I want the above data to be used.

I want to use a drop down menu to select a different radius. Lets say 30 miles. I want to update the page so that the above line of code will update and look like this.

map.centerAndZoom(new GPoint(-79.89505, 40.85708), 30);

Here is some sections of code I am using.

<form action='<?php echo $_SERVER['PHP_SELF'];?>' method='post'>
<select name="radius" class="selectBoxes">
<option value="20">20 miles</option>
<option value="30">30 miles</option>
<option value="40">40 miles</option>
</select>
<input type='submit' name='submit' value='Click To Update Map'>
</form>

<script>

map.centerAndZoom(new GPoint(-79.89505, 40.85708), 10);

</script>

Shanee

7:45 pm on Aug 8, 2006 (gmt 0)

10+ Year Member



dear outdoorxtreme1
can you show me the whole code of
map.centerAndZoom(new GPoint(-79.89505, 40.85708), 10);

maybe after that i can help you

thanks

outdoorxtreme1

9:58 pm on Aug 8, 2006 (gmt 0)

10+ Year Member



Here is what I have but I cant get the radius and centerPoint drop down menu data to change when I click the button to post. It stays as defined in these two lines.

if(!isset($radius) or strlen($radius)<1) $radius="9";

if(!isset($center) or strlen($center)<1) $center="-80.814554, 41.238206";

<?php
include_once("map.inc");
?>

<html>
<body bgcolor="#004F00">
<table border="0" cellpadding="0" cellspacing="0">
<tr><td width="724" height="38" border="0"><center>
<a href="javascript:print();"><img src="/uploads/images/print.jpg" name="print" width="158" height="38" border="0" onmouseover="imageRoll(this);" onmouseout="imageOut(this);" /></a><a href="javascript:close();"><img src="/uploads/images/close.jpg" name="close" width="66" height="38" border="0" onmouseover="imageRoll(this);" onmouseout="imageOut(this);" /></a></center>
</td>
</tr>
<tr><td align="left" width="724" valign="top">
<div>
<table width="724" height="96" cellpadding="0" cellspacing="0" background="/uploads/images/formBG.jpg" style="background-repeat:no-repeat;">
<tr><td colspan="6"><img src="/uploads/images/a.gif" width="724" height="15" /></td>
</tr><form action='<?php echo $_SERVER['PHP_SELF'];?>' method='post'>
<tr><td width="58"><img src="/uploads/images/formShow.gif" width="61" height="16" /></td>
<td width="114" align="left"><select name="searchCategory" class="selectBoxes">
<?php
$link = mysql_connect("$host", "$user", "$password") or die("Could not connect: " . mysql_error());
mysql_selectdb("$database",$link) or die ("Can\'t use server : " .mysql_error());
//get all types from table

$result = mysql_query("SELECT DISTINCT type FROM wholocations group by type",$link);
if (!$result)
{
echo "no results ";
}
while($row = mysql_fetch_assoc($result))
{
echo "<option value=\"".$row['type']."\">".$row['type']."</option> ";
}
?>
</select></td>
<td width="59"><img src="/uploads/images/formWithin.gif" width="62" height="16" /></td>
<td width="84" align="left"><select name="radius" class="selectBoxes">

<option value="2">20 miles</option>
<option value="3">30 miles</option>
<option value="4">40 miles</option>
<option value="5">50 miles</option>
</select></td>
<td width="26"><img src="/uploads/images/formOf.gif" width="28" height="16" /></td>
<td width="383" align="left"><select name="centerPoint" class="selectBoxes">

<option value="-80.814554, 41.238206">Warren, OH</option>
<option value="-79.89505, 41.000000">Test</option>

</select></td>
</tr>
<tr><td colspan="6" align="center"><br>
<input type='submit' name='submit' value='Click To Update Map'>
</form>
</td></tr></table>
</div>

<div id="map" style="width: 714px; height: 471px; border:5px solid #009900; margin-top:4px;"></div>

</td></tr></table>

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

// Global Variables
// set map variable
var map = "";
//set up array of locations
var aLocations = new Array;
// Storage for sidebar list
var listNodeContent = "";

// Create marker icon
var iconsm = new GIcon();
iconsm.iconSize = new GSize(43, 63);
iconsm.iconAnchor = new GPoint(21, 63);
iconsm.infoWindowAnchor = new GPoint(21, 15);

<?php
//get the first result if a category was selected
if(isset($_REQUEST['centerPoint'])) $result = mysql_query("SELECT * FROM wholocations where type='".$_REQUEST['centerPoint']."' LIMIT 1",$link);
$row = mysql_fetch_array($result);
$center=$row['center'];
//if no category was selected, these results won't exist, so define default values
if(!isset($center) or strlen($center)<1) $center="-80.814554, 41.238206";

if(isset($_REQUEST['radius'])) $result = mysql_query("SELECT * FROM wholocations where type='".$_REQUEST['radius']."' LIMIT 1",$link);
$row = mysql_fetch_array($result);
$radius=$row['radius'];
//if no category was selected, these results won't exist, so define default values
if(!isset($radius) or strlen($radius)<1) $radius="9";
?>

var map = new GMap(document.getElementById("map"));
// Map type: map, satellite, hybrid
map.setMapType(map.getMapTypes()[0]);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
// Center the map to the default location
map.centerAndZoom(new GPoint(<?php echo $center;?>), <?php echo $radius;?>);

// CREATES A MARKER WHOSE INFO WINDOW DISPLAYS THE GIVEN NUMBER

function createMarker(point, number, iconsm)

{
var marker = new GMarker(point, iconsm);

// SHOW THIS MARKERS INDEX IN THE INFO WINDOW WHEN IT IS CLICKED

var html = number;
GEvent.addListener(marker, 'click', function() {marker.openInfoWindowHtml(html);});
return marker;
};

<?php
$link = mysql_connect("$host", "$user", "$password") or die("Could not connect: " . mysql_error());
mysql_selectdb("$database",$link) or die ("Can\'t use server : " .mysql_error());
if(isset($_REQUEST['searchCategory'])) $result = mysql_query("SELECT * FROM wholocations where type='".$_REQUEST['searchCategory']."'",$link);
else $result = mysql_query("SELECT * FROM wholocations",$link);
if (!$result)
{
echo "no results ";
}
while($row = mysql_fetch_array($result))
{
?>
var point = new GPoint(<?php echo $row['lon'] . "," . $row['lat'];?>);
var footerHtml = "<div id=\"MapBuilderIWFooter\"><h1><a href=\"#\" onclick=\"ZoomMapTo(0)\">Zoom To</a></h1></div>";
// Define Marker
iconsm.image = "http://www.somesite.com/map/images/marker_20_<?php echo $row['colour'];?>.png"; var InfoHTML = "<br><?php echo $row['desc'];?><br>Latitude:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['lat'];?><br>Longitude:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['lon'];?><br><?php echo '<a href=\"javascript:void(0);\" onclick=\"fullScreen(\'/index.php?page=TESTPOP&trip=',$row['id'],'\');\">Click for details</a><br>';?>"

var marker = createMarker(point, InfoHTML, iconsm);
map.addOverlay(marker);
<?php
}
mysql_close($link);
?>

//]]>
</script>
</body>
</html>

[edited by: dreamcatcher at 10:05 pm (utc) on Aug. 8, 2006]
[edit reason]
[1][edit reason] Generalized url. See TOS [webmasterworld.com] [/edit]
[/edit][/1]

outdoorxtreme1

10:36 pm on Aug 8, 2006 (gmt 0)

10+ Year Member



It will only show the default values each time I click the update page button.

Here is the centerPoint values I wat to use:
<select name="centerPoint" class="selectBoxes">
<option value="-80.814554, 41.238206">Warren, OH</option>
<option value="-79.89505, 41.000000">Test</option>
</select>

<?
if(isset($_REQUEST['centerPoint'])) $result = mysql_query("SELECT * FROM wholocations where type='".$_REQUEST['centerPoint']."' LIMIT 1",$link);
$row = mysql_fetch_array($result);
$center=$row['center'];
//if no category was selected, these results won't exist, so define default values
if(!isset($center) or strlen($center)<1) $center="-80.814554, 41.238206";
?>

Here is where I want the data to go:

map.centerAndZoom(new GPoint(<?php echo $center;?>), 10);

By the way. I want to use the data from the option values and not from MySQL tables.

outdoorxtreme1

10:56 pm on Aug 8, 2006 (gmt 0)

10+ Year Member



I got it to work!

if(isset($_REQUEST['centerPoint']))
$row = $_REQUEST['centerPoint'];
$center=$row['center'];
//if no category was selected, these results won't exist, so define default values
if(!isset($center) or strlen($center)<1) $center="-80.814554, 41.238206";

Anybody have a clue on how to get the selected option to reflect what is shown after an update? It currently shows the first option in order.