In the code example below I have made window.status alternate from “a” to “b”
function alternateViaIntrvl() {
setInterval('alterStatus()', 500);
}
var altrCounter = 0;
function alerted() {
var txt = "a";
if (altrCounter % 2 == 0) {
txt = "b"
}
window.status=txta;
countalerted++;
}
I was just trying to make an alternate Ajax watermark
from “insert date” to “mm/dd/yyyy” but it got too complicated accessing ajax with javascript
set_Text("mm/dd/yyyy")
I then found an alternative to ajax : javascriptWaterMark by Md.Asaduzzaman Azad
and I tried to implement a setInterval() on that code,
so I will be able to have a neat dual mode JavaScript-Watermark.
I know it must be simple as in the example of window.status alternate code but I couldn’t figure out for myself how to implement it .
JavaScript
function Focus(objname, waterMarkText) {
obj = document.getElementById(objname);
if (obj.value == waterMarkText) {
obj.value = "";
obj.className = "NormalTextBox";
if (obj.value == "insert date" || obj.value == "" || obj.value == null) {
obj.style.color = "black";
}
}
}
function Blur(objname, waterMarkText) {
var alternateWM1 = "insert date";
var alternateWM2 = "mm/dd/yyyy";
count++;
obj = document.getElementById(objname);
if (obj.value == "") {
obj.value = waterMarkText;
if (objname != "txtPwd") {
obj.className = "WaterMarkedTextBox";
}
else {
obj.className = "WaterMarkedTextBoxPSW";
}
}
else {
obj.className = "NormalTextBox";
}
if (obj.value == "insert date" || obj.value == "" || obj.value == null) {
obj.style.color = "gray";
}
}
- 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 actually a hidden table row that the default state is hidden
and then on imageButton click event(Codebehind)it’s made visible
TRinsertForm.Style.Add("visibility", "visible");
so i guess that i could run a script form code behind that will generate javascript code that will set textbox initial text or somthing else.
this is what i came up with :
see html code in order to set it up as perfect alternating Watermark as i could come up with
using javascript and ajax methods combined