• Resolved saityalex

    (@saityalex)


    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 7 years, 2 months ago by saityalex.
Viewing 1 replies (of 1 total)
  • Plugin Author sevenspark

    (@sevenspark)

    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.