Explore my side projects and work using this link

Upsidedown is a WordPress theme design that brings blog posts rising above inverted header and footer components.

JQuery – select 변경 form sumbit

Written in

by

Advertisements

select box 값을 변경하면 자동으로 form submit() 해 버리고 싶은데, 어떻게 하나요? 엄청 간단하게 알려주세요. 🙂

How to Submit Form on Select Change
I have the following form. I’d like it to be submitted automatically via jQuery when the user makes a selection, without needing to press the submit button. How do I do this? <form action=”″ me…

정답은 아래 코드를 참고하세요

$(document).ready(function() {  $('#선택박스아이디').on('change', function() {     document.forms[myFormName].submit();  });});// 혹은$(document).ready(function() {   $('#선택박스아이디').change(function() {     var parentForm = $(this).closest("form");     if (parentForm && parentForm.length > 0)       parentForm.submit();   });});

쉽죠 끝.

on(‘change’) vs .change()

참고로 이벤트 등록을 2가지 형태로 할 수 있는데, 머가 맞는거니?

둘다 맞는데, 머 정답이라기 보다는 그냥 on(이벤트, function() {}); 형태로 사용하는 것을 강권합니다.

JQuery 클릭 이벤트 on(“click”) 과 click() 의 차이
JQuery on(“click”)과 click() on(“click”) 과 click() 의 차이점은 동적으로 이벤트를 바인딩할 수 있는지의 차이다. on(“click”)은 동적으로 가능하고 click()은 최초에 선언된 element에만 동작한다. 아래 예..

동적으로 생성된 요소의 경우 이벤트도 발생하게 하려면 on 을 써야 한다네요. 진짜끝

Advertisements