2013-02-17 3 views
0

저는 몇 시간 동안이 작업을 해왔습니다. 내 양식 중 하나만 작동하거나 전혀 작동하지 않습니다. 나는 폼 함수를 얻거나 아무것도 할 수없는 함수를 제출할 수 없다. 그것은 단지 모든 것을 불가능하게하고 제출하지 않습니다. 어떤 도움을 주셔서 감사합니다.jQuery는 입력을 기반으로 다른 양식을 모든 숫자 또는 문자로 제출하도록합니다.

기본적으로 첫 번째 양식의 입력 필드 인 "s-webref"의 항목을 기반으로 제출하려는 두 가지 양식이 있습니다.

"s-webref"에 숫자가 모두 입력 된 경우 첫 번째 양식 인 "property-webref-search"를 제출하십시오.

그렇지 않은 경우 두 번째 양식 "속성 검색"을 제출하십시오. (상단에 위치)

내 첫 번째 양식 :

 <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> 

내 두 번째 형태 :

$('#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(); 
}}); 
: 이것은 그 형태가 전혀 작동하지하게 사용되는 자바 스크립트가

 <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> 

+1

너는 자바 스크립트 (유효성 검사 외에) – VeXii

+0

@VeXii 실패한 자바 스크립트를 추가하기 위해 편집 됨. 나는 그것이 좋을 것이라고는 생각하지 않지만. –

답변

2

제출 버튼의 기본 동작을 방해하지 않으므로 양식이 항상 제출됩니다.

$('#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(); 
    } 
}); 
+0

이 코드는 아무 것도하지 않는 것 같습니다. 첫 번째 양식은 항상 제출됩니다. 또는 최소한 코드는 내 페이지에서이 방법으로 작동합니다. –

+1

작동해야합니다. 문서에서 이미 포장 했습니까? – adeneo

+0

예, 그것은 내부의 \t \t \t \t \t jQuery를 (문서) .ready (함수 ($) { 어쩌면 내 형태의 구조가 제출 될 수있는에서 두 번째 방지는?이 날 미치게되었습니다 정확히입니다 지난 4 시간 동안 jquery가 추가 된 후 두 번째 양식은 더 이상 제출되지 않습니다 –

관련 문제