Note that there are some explanatory texts on larger screens.

plurals
  1. POCall of function not working
    primarykey
    data
    text
    <p>I think I'm having a problem with the <code>this</code> element in the code below</p> <p>I'm trying to call a function in two way's but the second way dosen't work:</p> <p>The function validate_email is not responding, I think the call for it is wrong in the second example. </p> <p><strong>The working way is:</strong></p> <pre><code>checking = {}; checking.form = function(){ return{ validate_mail: function(a){ var c=true; var email_filter = /^[\w.-]+@[\w.-]+([\.]+([\w]+[\.])?)+[a-zA-Z]{2,6}$/i; if( $.trim(a)!="" &amp;&amp; !$.trim(a).match(email_filter) ) c=false; return c; }, check_mail: function(div_id, error) { var email = $(div_id + ' input[name=email]').val(); var check = this.validate_mail(email); if(check==false &amp;&amp; $(div_id).is(':visible') ) { $(div_id + ' '+ error).html('&lt;b&gt;some error&lt;/b&gt;'); } else { $(div_id + ' ' + error).text(''); } } } }(); $(function(){ $('#register input[name=email]').blur(function(){ checking.form.check_mail("#register", ".error_email"); }); } </code></pre> <p><strong>The not working way is:</strong></p> <pre><code>checking = {}; checking.form = function(){ return{ validate_mail: function(a){ var c=true; var email_filter = /^[\w.-]+@[\w.-]+([\.]+([\w]+[\.])?)+[a-zA-Z]{2,6}$/i; if( $.trim(a)!="" &amp;&amp; !$.trim(a).match(email_filter) ) c=false; return c; }, check_mail: function(div_id, error) { return function(){ //**made the change nr. 1** var email = $(div_id + ' input[name=email]').val(); var check = this.validate_mail(email); if(check==false &amp;&amp; $(div_id).is(':visible') ) { $(div_id + ' '+ error).html('&lt;b&gt;some error&lt;/b&gt;'); } else { $(div_id + ' ' + error).text(''); } } } } }(); $(function(){ //**made the change nr. 2** $('#register input[name=email]').blur( checking.form.check_mail("#register", ".error_email") ); } </code></pre> <p>I need some help with this. I believe I'm not useing the <code>this</code> element in the right way</p> <p>Any help is appreciated !!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload