In the following code snippet, I have implemented a function to make window.status
switch between displaying "a" and "b."
function alternateViaIntrvl() {
setInterval('alterStatus()', 500);
}
var altrCounter = 0;
function alerted() {
var txt = "a";
if (altrCounter % 2 == 0) {
txt = "b"
}
window.status=txta;
countalerted++;
}
Initially, I attempted to create an alternating Ajax watermark that switched between displaying "insert date" and "mm/dd/yyyy." However, this became too complex when trying to access Ajax with JavaScript.
To achieve this effect, I utilized the set_Text("mm/dd/yyyy")
method.
Upon further exploration, I came across an alternative solution to Ajax: javascriptWaterMark by Md.Asaduzzaman Azad.
I then attempted to incorporate a setInterval()
function into the existing code base in order to create a dual-mode JavaScript Watermark functionality.
While the implementation seemed straightforward, akin to the example showcasing the alternation of window.status
, I struggled to replicate the same behavior for my specific use case.
The following snippet illustrates the JavaScript functions Focus and Blur:
function Focus(objname, waterMarkText) {
// Function logic here
}
function Blur(objname, waterMarkText) {
// Function logic here
}
- html
<table>
<tr>
<td>
User Id
</td>
<td>
<asp:TextBox ID="txtUserId" runat="server"
onfocus="Focus(this.id,'insert date')"
onblur="Blur(this.id,'insert date')"
Width="126px" CssClass="WaterMarkedTextBox">
insert date
</asp:TextBox>
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<asp:TextBox ID="txtPwd" TextMode="Password" runat="server"
onfocus="Focus(this.id,'')"
onblur="Blur(this.id,'')" Width="126px"
CssClass="WaterMarkedTextBoxPSW" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit" />
</td>
</tr>
</table>
</form>
This is essentially a hidden table row that remains invisible by default, only becoming visible upon clicking an image button event in the Codebehind.
TRinsertForm.Style.Add("visibility", "visible");
As a potential workaround, I considered running a script from the code behind to generate JavaScript code that could set the initial text for the textbox or perform other actions as needed.