I’m using the AJAX Control Toolkit control “TextBoxWaterMarkExtender”. The problem originally was that in Firefox, setting the text with javascript like so:
var getDateField = document.getElementById('soandso');
getDateField.value = 'someandsome';
Would be cleared on submit/post because the Extender control thought that nobody had edited it, so it was clearing the “watermark”.
I followed this workaround: http://www.mindfiresolutions.com/Workaround-for-TextBoxWatermarkExtender-of-AjaxControlToolkit–855.php
and it works great in Firefox, but IE says “‘null’ is null or not an object” on this line:
var dateIdentified = $find("Beh" + sender).get_Text();
Anything obvious that I’m missing?
Edit: Sorry guys, I thought $find was a jQuery function.
Edit: More code:
function dateToday(sender)
{
var dateIdentified = $find("Beh" + sender).get_Text();
if (dateIdentified.length == 0)
{
var todaydate = new Date();
var smonth = todaydate.getMonth() + 1;
var sday = todaydate.getDate();
var syear = todaydate.getFullYear();
$find("Beh" + sender).set_Text(smonth.toString() + '/' + sday.toString() + '/' + syear.toString());
}
}
WaterMark:
<toolkit:TextBoxWatermarkExtender BehaviorID="BehSTART_DATE" ID="WaterMarkSTART_DATE" runat="server"
TargetControlID="dcSTART_DATE"
WaterMarkText="mm/dd/yyyy" WaterMarkCssClass="searchHint" />
For anyone interested to know, I switched from using body onLoad to call my javascript function to
as this article suggested: http://blogs.telerik.com/dimodimov/posts/08-12-13/don_t_use_body_onload_in_asp_net_ajax_websites.aspx
Now IE, Firefox and Chrome all see a value for the $find.