wordpress - Count length of one input field and print it in another with Gravity Forms and Javascript -
i using gravity forms wordpress , trying figure out how count length of characters user types 1 of input boxes , print number input box in same form. think can done javascript total newb , here watered down effort. can see trying do.
<!-- edited --> <form> <input name="input_10" id="input_1_10" type="text" value="" class="small" tabindex="1"> <input name="input_2" id="input_1_2" type="text" value="" class="medium" tabindex="2"> <div style="padding:10px 15px; font-family:sans-serif !important;"> <p id="preview" style="text-align:center;font-size:22px;font-weight:bold;">sample text</p> </div> </form> <script> var bank = document.getelementbyid("input_1_2"); var countnum = document.getelementbyid("input_1_10"); bank.addeventlistener("keyup", function(e) { countnum.value = bank.value.length; }); document.getelementbyid("preview").innerhtml= countnum.value; </script>
so user type "message" in #input_1_10 , need way count characters(preferably without counting spaces) , print them in #input_1_2 before user submits form.
** edit: know how write value of #input_1_2 in paragraph id of #preview. **
thanks looking ;)
add eventlistener
first input. in case, whenever user presses , releases key, length of input displayed in second input.
<form> <input name="input_10" id="input_1_10" type="text" value="" class="small" tabindex="1"> <input name="input_2" id="input_1_2" type="text" value="" class="medium" tabindex="2"> </form> <script> var bank = document.getelementbyid("input_1_10"); var countnum = document.getelementbyid("input_1_2"); bank.addeventlistener("keyup", function(e) { countnum.value = bank.value.length; }); </script>
Comments
Post a Comment