I have a Web form built in Gravity Forms that is working quite well, But the users would like me to force Focus into the first field on the form when the form opens. I thought I could do this with a javascript function but it does not seem to work .. I know I am missing something just not sure what - Hopefully someone will see the error of my ways (code) and can point me in the right direction.. The function on keypress works the function to set the focus initially does not. Looking at the .ready documentation, but not sure that is the way I need to go.
[code]
<script type="text/javascript">
jquery(function($){
$('input[name=Badge]').focus();
});
jQuery(function($){
$("form").keypress(function(e) {
//Enter key
if (e.which == 13) {
return false;
}
});
});
</script>
[/code]
Thank you, that makes sense, but it does not work. I still have to use the mouse and set the focus in the first field which I believe to be named input_13 now not Badge.
Here is the code I see for the first field in the View Source option of the browser
[code]
<script type="text/javascript">
jQuery( document ).ready(function() {
$("input[name=input_13").focus();
});
jQuery(function($){
$("form").keypress(function(e) {
//Enter key
if (e.which == 13) {
return false;
}
});
});
</script>
<div id="field_2_13" class="gfield gfield--width-full gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" >
<label class='gfield_label' for='input_2_13' >Badge<span class="gfield_required"><span class="gfield_required gfield_required_asterisk">*</span></span></label>
<div class='ginput_container ginput_container_number'>
<input name='input_13' id='input_2_13' type='text' value='' class='small' placeholder='Scan you Badge' aria-required="true" aria-invalid="false" aria-describedby="gfield_instruction_2_13" />
<div class='instruction ' id='gfield_instruction_2_13'>Please enter a number from <strong>999</strong> to <strong>99999</strong>.</div></div></div>
[/code]