I have function as follows:
Mask (sender) {
var error= false;
var regex = '^[0-9]+,[0-9][0-9]$';
if(!($(sender).val().match(regex))) {
error = true;
}
}
HTML
<input name="mf1234" value="" id="mf1234" onblur="Mask(this)"/>
<span class="comment" id="mf1234" class="sssnnn"></span>
I am calling onBlur using (this), but if I want to call it by Mask (this.id) with span id, how can I change my method code?
JQuery takes the CSS selector values, so any ID’s need to be represented as #idValue
<div id='MyId'>would be called in jQuery as$("#MyId")So if you plan on passing
Mask(this.id)tofunction Mask (senderID)you need to call$("#" + senderID)You can call this from the HTML like so, however inline Javascript is not recommended.
Look into Code Seperation.
Here is the better solution…
attach your events in the javascript.. this avoids inline javascript and promotes code separation. This will aid you in Maintainability and Readability
ohh and then you html will look like this
http://jsfiddle.net/rlemon/NCwF3/