alander
Well-known member
Hi I need my javascript to communicate with my asp.net textbox control, I am using VS 2008, framework 3.5
this is my code for my controls
When i view the source code of my browser when i Run the program
It shows me this
I am sure getelementbyid will work, but I dont understand why its not working
document.getElementById('<%=txtLng.UniqueID%>') gives me ctl00$cphCENTER$txtLng but i need ctl00_cphCENTER_txtLat
Its urgent, please help me
I tried this too, cant work either
How to put value in asp.net textbox from javascript?
Thanks in advance
this is my code for my controls
VB.NET:
<asp:Content ID="Content3" ContentPlaceHolderID="cphCENTER" runat="server">
<center>
<div id="map" style="width: 50%; height: 250px; margin-bottom: 10px">
</div>
</center>
<div style="width: 95%;">
<form id="adminForm" action="#">
<table>
[snip]
<tr>
<th style="width: 40%; height: auto" align="right">
Search For:
</th>
<td align="left" style="width: 39%; height: 22px">
<input type="text" name="address" size="250" value="Orchard Road" style="width: 220px" />
</td>
<td align="left" style="width: 20%; height: 22px">
<input type="button" value="Find" class="button" onclick="javascript:getAddress(address.value)" />
</td>
</tr>
<tr>
<th style="width: 40%; height: auto" align="right">
Latitude:
</th>
<td align="left" style="width: 59%; height: 22px">
<asp:TextBox ID="txtLat" runat="server" Width="220px"></asp:TextBox>
</td>
</tr>
<tr>
<th style="width: 40%; height: auto" align="right">
Longtitude:
</th>
<td align="left" style="width: 59%; height: 22px">
<asp:TextBox ID="txtLng" runat="server" Width="220px"></asp:TextBox>
</td>
</tr>
</table>
</form>
</div>
VB.NET:
<script type="text/javascript" src="http://gothere.sg/jsapi?sensor=false"></script>
<script type="text/javascript">
gothere.load("maps");
var map, geocoder;
function initialize() {
if (GBrowserIsCompatible()) {
// Create the Gothere map object.
map = new GMap2(document.getElementById("map"));
// Set the center of the map.
map.setCenter(new GLatLng(1.362083, 103.819836), 13);
// Add zoom controls on the top left of the map.
map.addControl(new GSmallMapControl());
// Add a scale bar at the bottom left of the map.
map.addControl(new GScaleControl());
// Create a geocoder object.
geocoder = new GClientGeocoder();
}
}
var lat, lng;
function getAddress(address) {
map.clearOverlays()
if (geocoder) {
geocoder.getLatLng(address, function(latlng) {
if (!latlng) {
alert("Opps, " + address + " not found.");
} else {
// Center the map at the address and draw a marker.
map.setCenter(latlng, 11);
var marker = new GMarker(latlng);
map.addOverlay(marker);
marker.openInfoWindowHtml("<h4>" + address + "</h4>"); // + " <br> Latitude: " + latlng.lat() + " <br> Longitude: " + latlng.lng());
adminForm.txtLat.value = latlng.lat() //I tried this not working
adminForm.txtLng.value = latlng.lat()
document.getElementById('<%=txtLat.UniqueID%>').value = latlng.lat() //I tried this not working too
document.getElementById('<%=txtLng.UniqueID%>').value = latlng.lng()
}
});
}
}
gothere.setOnLoadCallback(initialize);
</script>
When i view the source code of my browser when i Run the program
It shows me this
VB.NET:
<tr>
<th style="width: 40%; height: auto" align="right">
Search For:
</th>
<td align="left" style="width: 39%; height: 22px">
<input type="text" name="address" size="250" value="Orchard Road" style="width: 220px" />
</td>
<td align="left" style="width: 20%; height: 22px">
<input type="button" value="Find" class="button" onclick="javascript:getAddress(address.value)" />
</td>
</tr>
<tr>
<th style="width: 40%; height: auto" align="right">
Latitude:
</th>
<td align="left" style="width: 59%; height: 22px">
<input name="ctl00$cphCENTER$txtLat" type="text" id="ctl00_cphCENTER_txtLat" style="width:220px;" />
</td>
</tr>
<tr>
<th style="width: 40%; height: auto" align="right">
Longtitude:
</th>
<td align="left" style="width: 59%; height: 22px">
<input name="ctl00$cphCENTER$txtLng" type="text" id="ctl00_cphCENTER_txtLng" style="width:220px;" />
</td>
</tr>
VB.NET:
//document.getElementById('ctl00$cphCENTER$txtLat').value = latlng.lat()
//document.getElementById('ctl00$cphCENTER$txtLng').value = latlng.lng()
I am sure getelementbyid will work, but I dont understand why its not working
document.getElementById('<%=txtLng.UniqueID%>') gives me ctl00$cphCENTER$txtLng but i need ctl00_cphCENTER_txtLat
Its urgent, please help me
I tried this too, cant work either
How to put value in asp.net textbox from javascript?
Thanks in advance
Last edited: