• Resolved niceandripe

    (@niceandripe)


    Hi
    i want to specify a custom field that has a class applied to the text input in my custom post type.

    so I have a custom post type for ‘Events’ that has a custom field of ‘Date’ and the input for that field has a class of ‘date-calendar’ so i can then use jquery ui calendar on it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter niceandripe

    (@niceandripe)

    bump

    Thread Starter niceandripe

    (@niceandripe)

    OK, can I use javascript to detect when the option value of ‘date’ is selected and apply a class of ‘date-calendar’ to the text input field?

    <select id="metakeyselect" name="metakeyselect" tabindex="7">
      <option value="#NONE#">&mdash; Select &mdash;</option>
      <option value='date'>date</option>
    </select>
    
    <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />

    Using jQuery:

    $(document).ready(function(){
      $('#metakeyselect').change(function(){
        if($(this).val() == 'date'){
          $('#metakeyinput').addClass('date-calendar'); // adds class
        }else{
          $('#metakeyinput').removeClass('date-calendar'); // removes class if it already exists, otherwise will carry on.
        }
      });
    });

    can do a vanilla JavaScript if needed?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘specify custom field with class in a custom post type?’ is closed to new replies.