I’ve been trying to do this for hours. Either only one of my forms works or none at all. I can’t get the form function or submit function to do anything. it just disables the whole thing and doesn’t submit. Any help is appreciated.
Basically I have two forms that I want to submit based on the entry in the first form’s input field, “s-webref”.
If “s-webref” has input which is all numbers, submit the first form: “property-webref-search”.
If not, submit the second 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 second 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 is the javascript that I used that makes form not work at 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 is always submitting, as you are not preventing the default action of the submit button: