bobbiloo
bobbiloo

Reputation: 432

jquery alternatives to change function

So I'm using jquery to detect the change in an ID element in my form, like this:

$(document).ready(function(){
    $('#ID_a').change(function(){
        if(<<<some condition>>>){
            $('#ID_a').append(<<<more info>>>)
        }
    })
});

But I'm finding my site visitors aren't seeing the appended content because they aren't clicking off of the ID element because it's the last field in my form. They are just clicking the submit button. What can I do to help them see the appended content, which are new fields requesting additional info on the form? (Aside from completely redesigning my form)

Upvotes: 0

Views: 1021

Answers (3)

Wouter J
Wouter J

Reputation: 41934

Add a .submit event to the form:

$(document).ready(function() {
  var appendedText = false;

  function appendFormContent( elem ) {
     elem.append('some text');
     appendedText = true;
  }

  $('#the-form').submit(function() {
    if( !appendedText ) { 
      // content not appended
      appendFormContent( $('#some-id') );
      return false;
     }
  });

  $('#some-option').change(function() {
    appendFormContent( $('#some-id') );
  });

});

Upvotes: 0

Francis Lewis
Francis Lewis

Reputation: 8980

One option you could use is focus for an input field, so if they start typing in data, you could append the content.

Upvotes: 0

James Montagne
James Montagne

Reputation: 78650

You could use one of the key events (such as keypress or keydown) to show the fields as soon as they type anything.

Upvotes: 2

Related Questions