Tuesday, 13 August 2013

Variable 'name' issue in chrome

Variable 'name' issue in chrome

<input id="Name" name="Name" tabindex="0" type="text" value="Name:" />

<script type="text/javascript">
    var name = $("#Name");
    name.focus(function () {if ($(this).val() == "Name:") $(this).val('');});
    name.blur(function () {if ($(this).val() == "") $(this).val("Name:");});
</script>

solution:
Somehow Chrome doesn't like your variable to be named "name" in this case. The following works

<script type="text/javascript">
    var name2 = $("#Name");
    name2.focus(function () {if ($(this).val() == "Name:") $(this).val('');});
    name2.blur(function () {if ($(this).val() == "") $(this).val("Name:");});
</script>

No comments:

Post a Comment