javascript - jQuery to trigger submitting of different forms based on input being all numbers or just letters -
i've been trying hours. either 1 of forms works or none @ all. can't form function or submit function anything. disables whole thing , doesn't submit. help appreciated.
basically have 2 forms want submit based on entry in first form's input field, "s-webref".
if "s-webref" has input numbers, submit first form: "property-webref-search".
if not, submit sec form "property-search".
my first form (located on top):
<form name="property-webref-search" id="property-webref-search" method="get" action="<?php bloginfo('url'); ?>/"> <input type="text" class="text webref" id="s-webref" name="s" value="<?php _e('İlan no veya arama', 'woothemes'); ?>" onfocus="if (this.value == '<?php _e('İlan no veya arama', 'woothemes'); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e('İlan no veya arama', 'woothemes'); ?>';}" /> <input type="submit" class="submit button" name="property-search-webref-submit" id="property-search-webref-submit" value="<?php _e('ara', 'woothemes'); ?>" /> </form>
my sec form:
<form name="property-search" id="property-search" method="get" action="<?php bloginfo('url'); ?>/"> <input type="text" class="main-query text" id="s-main" name="s" value="<?php if ( $keyword != '' ) { echo $keyword; } else { _e('arama...', 'woothemes'); } ?>" onfocus="if (this.value == '<?php _e('arama...', 'woothemes') ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e('arama...', 'woothemes') ?>';}" /> <input class="view-button" type="submit" value="<?php _e('ara', 'woothemes') ?>" name="property-search-submit" /> </form>
this javascript used makes form not work @ all:
$('#property-search-webref-submit').click(function() { var searcherz = $("input#s-webref").val(); if(searcherz.match(/^\d+$/)) { $('form#property-webref-search').submit(); } else { $('form#property-search').submit(); }});
the form submitting, not preventing default action of submit button:
$('#property-search-webref-submit').click(function(e) { e.preventdefault(); var searcherz = $("#s-webref").val(); if( /^\d+$/.test(searcherz) ) { $('#property-webref-search').get(0).submit(); } else { $('#property-search').get(0).submit(); } });
javascript jquery html forms submit
No comments:
Post a Comment