Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot disable onclick/onblur values for text field via jQuery

What I have

I have a text field, the mark-up of which I cannot directly edit:

<input type="text" name="email" value="Email Address" id="subscribe-field" 
onclick="if ( this.value == 'Email Address' ) { this.value = ''; }" 
onblur="if ( this.value == '' ) { this.value = 'Email Address'; }">

What I need

I need the text field value to be blank regardless of whether the text field is clicked, not clicked or clicked out of.

What I've tried

I can disable the value:

$('#subscribe-field').val('');

I've tried to disable the onclick and onblur values:

$('#subscribe-field').click(function() { return false; });
$('#subscribe-field').off('click');
$('#subscribe-field').unbind('click');

...however, the value reappears as soon as I click outside of the text field.

My question

How do I remove the onblur value from the above mark-up?

like image 937
Dominor Novus Avatar asked Oct 11 '12 11:10

Dominor Novus


People also ask

Does Onblur fires before Onclick?

The divs inside the menu also have onclick() events which execute the special processing. The problem is that the onclick() events never fire when the menu is clicked, because the input field's onblur() fires first and deletes the menu, including the onclick() s!

How do I cancel my blur event?

The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does bubble. The opposite of blur is the focus event, which fires when the element has received focus. The blur event is not cancelable.

How check textbox is enabled or disabled in jquery?

You can use $(":disabled") to select all disabled items in the current context. To determine whether a single item is disabled you can use $("#textbox1").is(":disabled") . Save this answer.

What is Onblur Onfocus?

Definition and UsageThe onblur attribute fires the moment that the element loses focus. Onblur is most often used with form validation code (e.g. when the user leaves a form field). Tip: The onblur attribute is the opposite of the onfocus attribute.


1 Answers

try this way :

$('#subscribe-field').removeAttr('onclick');

$('#subscribe-field').removeAttr('onblur');

like image 141
Mahmoud Farahat Avatar answered Sep 22 '22 03:09

Mahmoud Farahat