Running length of text field

Running length of text field

Unread postby Tinka » Thu May 01, 2014 10:38 pm

Hi

I tried this solution in this post:
http://forums.nubuilder.com/viewtopic.php?f=15&t=8387&p=12550&hilit=characters#p12550.

It does not work for me. Would you please help?

What has the html object to be? I put an input box read-only:
Code: Select all
<input readonly type=text name=bases
size=3 value="0">


The Javascript function is on the Edit form's Javascript tab. I tried both the html-object name or object id form the zzzsys_object table.

Code: Select all
function nuLoadEdit() {
  $('#531dcb7d9bf9567').keyup(function () {
    var max = 30;
    var col = 'grey';
    var len = $(this).val().length;
    if (len >= max) {var col = 'red';}
    $('#bases')
      .text(len)
      .css('color', col);
  });
}


Tinka
Tinka
 
Posts: 73
Joined: Mon Feb 24, 2014 11:28 pm

Re: Running length of text field

Unread postby massiws » Sun May 04, 2014 4:46 am

Tinka,
your HTML object must have id="bases", so jQuery can select it.

Max
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Re: Running length of text field

Unread postby Tinka » Fri May 09, 2014 5:19 pm

Max,

thank you for your reply. My html object has the field name "bases", but do you mean the object id in the zzzsys_object table?

Is the syntax in the Javascript ok?

Tinka
Tinka
 
Posts: 73
Joined: Mon Feb 24, 2014 11:28 pm

Re: Running length of text field

Unread postby Tinka » Fri May 09, 2014 5:30 pm

Got it working! You can close the topic.
I changed the object name of the object with keyup from the id in the system table to the field name!

Code: Select all
function nuLoadEdit() {
  $('#prim_sekvens').keyup(function () {
    var max = 30;
    var col = 'grey';
    var len = $(this).val().length;
    if (len >= max) {var col = 'red';}
    $('#bases')
      .text(len)
      .css('color', col);
  });
}


Tinka
Tinka
 
Posts: 73
Joined: Mon Feb 24, 2014 11:28 pm

Re: Running length of text field

Unread postby Tinka » Fri May 09, 2014 6:11 pm

Any idea how to save the value of the running text length to the field afterwards (on After Save Custom Code)?
Tinka
 
Posts: 73
Joined: Mon Feb 24, 2014 11:28 pm

Re: Running length of text field

Unread postby massiws » Mon Jun 02, 2014 1:00 am

Tinka, do you want to store the length value in database?
If so, you should create a new field in your table and configure a text object on your form to map this field; alternatively, configure your "bases" field to map the new created DB field.
Then add a new line in your function to store the length value in DB field:
Code: Select all
function nuLoadEdit() {
    $('#prim_sekvens').keyup(function () {
        var max = 30;
        var col = 'grey';
        var len = $(this).val().length;
        if (len >= max) {var col = 'red';}
        $('#bases')
            .text(len)
            .css('color', col);
    });
    $('#my-db-field-name').val(len);
}


Max
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Re: Running length of text field

Unread postby Tinka » Tue Jun 03, 2014 7:12 pm

Thank you, I had figured it out.
Tinka
 
Posts: 73
Joined: Mon Feb 24, 2014 11:28 pm

Re: Running length of text field

Unread postby massiws » Wed Jun 04, 2014 5:03 am

.
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy


Return to Custom Code

Who is online

Users browsing this forum: No registered users and 4 guests