Title: Onblur function
Last modified: January 30, 2017

---

# Onblur function

 *  Resolved [saityalex](https://wordpress.org/support/users/saityalex/)
 * (@saityalex)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/onblur-function/)
 * Hello and thank you so much for the plugin.
 * I need some help with adding function onblur.
 * I have shortcode in my CF7
    [dynamictext your-city id:your-city “geoip_detect2
   property=’city'”] that displays city of a user.
 * The city name must be Capitalized so I use a fanction
 *     ```
       <script type=”text/javascript”>
       function upperCaseFirstLetters(ABC123) {
       var myTextObject = document.getElementById(ABC123);
       myTextObject.value = myTextObject.value.replace(/\W\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
       }
       </script>
       ```
   
 * Last, it should be added in <input> tag
 * `<input type=”text” name=”your-city” value=”Moscow” size=”40″ class=”wpcf7-form-
   control wpcf7dtx-dynamictext wpcf7-dynamictext” id=”your-city” aria-invalid=”
   false” onblur=”upperCaseFirstLetters(this.id)”>`
 * Help me to add this line onblur=”upperCaseFirstLetters(this.id)” for the input.
    -  This topic was modified 9 years, 4 months ago by [saityalex](https://wordpress.org/support/users/saityalex/).

Viewing 1 replies (of 1 total)

 *  Plugin Author [sevenspark](https://wordpress.org/support/users/sevenspark/)
 * (@sevenspark)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/onblur-function/#post-8720598)
 * Hi saityalex,
 * You should externalize your javascript. Bind an event from a separate JS file
   rather than mixing your javascript in with your HTML, which violates separation
   of concerns best practices.
 * e.g.
 *     ```
       jQuery( '#your-city' ).on( 'blur' , function(){
         upperCaseFirstLetters( jQuery( this ).attr( 'id' ) );
       });
       ```
   
 * I don’t think there’s a way to add an extra attribute to the form tag

Viewing 1 replies (of 1 total)

The topic ‘Onblur function’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7-dynamic-text-extension/assets/icon-256x256.
   png?rev=3019574)
 * [Contact Form 7 - Dynamic Text Extension](https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension/reviews/)

## Tags

 * [onblur](https://wordpress.org/support/topic-tag/onblur/)

 * 1 reply
 * 2 participants
 * Last reply from: [sevenspark](https://wordpress.org/support/users/sevenspark/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/onblur-function/#post-8720598)
 * Status: resolved