2014-11-25 3 views
-1

jQuery를 사용하여 양식을 제출하는 데 문제가 있습니다. Y는 이러한 옵션을 시도했지만 작동하지 않습니다.jQuery에서 양식 제출 관련 문제

1. Option 1: 

$("#servicio").change(function(){ 
    $(this).closest("#form1").trigger('submit'); 
}); 

2. Option 2 

$('select[name="servicio"]').change(function(){ 
     $(this).parents('form').submit(); 
}); 

3. Option 3 

$('#idComboBox').change(function(){ 
    $(this).closest('form').trigger('submit'); 
}); 

그건 내 완벽한 jQuery 코드입니다. 나는 선택 입력을 결합하기위한

<script> 
    (function($) { 
    $.widget("custom.combobox", { 
     _create: function() { 
     this.wrapper = $("<span>") 
      .addClass("custom-combobox") 
      .insertAfter(this.element); 

     this.element.hide(); 
     this._createAutocomplete(); 
     this._createShowAllButton(); 
     }, 

     _createAutocomplete: function() { 
     var selected = this.element.children(":selected"), 
      value = selected.val() ? selected.text() : ""; 

     this.input = $("<input>") 
      .appendTo(this.wrapper) 
      .val(value) 
      .attr("title", "") 
      .addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left") 
      .autocomplete({ 
      delay: 0, 
      minLength: 0, 
      source: $.proxy(this, "_source") 
      }) 
      .tooltip({ 
      tooltipClass: "ui-state-highlight" 
      }); 

     this._on(this.input, { 
      autocompleteselect: function(event, ui) { 
      ui.item.option.selected = true; 
      this._trigger("select", event, { 
       item: ui.item.option 
      }); 
      }, 

      autocompletechange: "_removeIfInvalid" 
     }); 
     }, 

     _createShowAllButton: function() { 
     var input = this.input, 
      wasOpen = false; 

     $("<a>") 
      .attr("tabIndex", -1) 
      .attr("title", "Mostrar todos") 
      .tooltip() 
      .appendTo(this.wrapper) 
      .button({ 
      icons: { 
       primary: "ui-icon-triangle-1-s" 
      }, 
      text: false 
      }) 
      .removeClass("ui-corner-all") 
      .addClass("custom-combobox-toggle ui-corner-right") 
      .mousedown(function() { 
      wasOpen = input.autocomplete("widget").is(":visible"); 
      }) 
      .click(function() { 
      input.focus(); 

      // Close if already visible 
      if (wasOpen) { 
       return; 
      } 

      // Pass empty string as value to search for, displaying all results 
      input.autocomplete("search", ""); 
      }); 
     }, 

     _source: function(request, response) { 
     var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i"); 
     response(this.element.children("option").map(function() { 
      var text = $(this).text(); 
      if (this.value && (!request.term || matcher.test(text))) 
      return { 
       label: text, 
       value: text, 
       option: this 
      }; 
     })); 
     }, 

     _removeIfInvalid: function(event, ui) { 

     // Selected an item, nothing to do 
     if (ui.item) { 
      return; 
     } 

     // Search for a match (case-insensitive) 
     var value = this.input.val(), 
      valueLowerCase = value.toLowerCase(), 
      valid = false; 
     this.element.children("option").each(function() { 
      if ($(this).text().toLowerCase() === valueLowerCase) { 
      this.selected = valid = true; 
      return false; 
      } 
     }); 

     // Found a match, nothing to do 
     if (valid) { 
      return; 
     } 

     // Remove invalid value 
     this.input 
      .val("") 
      .attr("title", value + " no coincide con ningun elemento") 
      .tooltip("open"); 
     this.element.val(""); 
     this._delay(function() { 
      this.input.tooltip("close").attr("title", ""); 
     }, 2500); 
     this.input.autocomplete("instance").term = ""; 
     }, 

     _destroy: function() { 
     this.wrapper.remove(); 
     this.element.show(); 
     } 
    }); 
    })(jQuery); 

    $(function() { 
    $("#servicio").combobox(); 
    $("#servicio").change(function(){ 
     alert("The text has been changed."); //doesn't works 
    }); 
    }); 

</script> 

HTML 코드를하는 PHP 코드를 사용하고 있습니다 :

<body> 

<div align="center"> 
<form name="form1" id="form1" method="post" action="solicitarcodeSERVICIO.php" target="destino"> 

    <table> 
    <tr> 
     <td>   
      <div class="ui-widget"> 
       <label>Seleccione el Servicio</label> 
       <select id="servicio" >     
        <? while($row = mysql_fetch_array($qServicios)) { ?> 
         <option value="<? echo($row["idServicio"]); ?>"> <? echo($row["nombre"]); ?></option> 
        <? } ?>   
       </select> 
      </div> 
     </td> 
    </tr> 
    <tr> 
     <td> 
      <input type="submit" value="Seleccionar"> 
     </td> 
    </tr> 
    </table> 
    </form> 
    <p>&nbsp; </p> 
    <hr /> 
    <div align="center"><iframe id="destino" name="destino" width="100%" height="800" frameborder="0"></iframe></div> 

</div> 

</body> 

나는 이미 그것에 대해 모든 게시물을 확인하고 결코 해결책은 내 경우에는 잘 작동하지 않습니다.

도와 주시겠습니까?

+0

어쩌면 문제는 귀하의 HTML에 어떤 이유로 게시하지 않은 것입니다. –

+0

죄송합니다, html 코드를 입력하십시오 – Dacar

답변

0

어쩌면 이것은 당신을 도울 수 있습니다

$('#SOMEID').on('change', function() { 
 
    $(this).parent('form').submit(); 
 
}); 
 

 
// This is just for testing purposes 
 
// (please remove it, unless you need it for other reasons) 
 
$('form').on('submit', function() { 
 
    alert('Form submited'); 
 
    return false; // prevents the form from submitting 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<form> 
 
    <select id="SOMEID"> 
 
    <option>Some Option 1</option> 
 
    <option>Some Option 2</option> 
 
    </select> 
 
</form>

Open with FIDDLE

참고 :이 답변 jQuery를 사용합니다. 로드되어 있는지 확인하십시오.

+0

안녕 Gonsalo, 당신의 제안은 작동하지 않습니다. 다른 해결책이 있습니까? – Dacar

+0

코드에서 정확히 무슨 일이 일어나고있는 피들을 만들 수 있습니까? –