form 질문 부탁드립니다..
본문
지난번에 물어서 해결이 되긴했는데..
다른 방식으로 짜야할 것 같아서...
여쭤보는 바 입니다 ㅠㅠ
--폼화면--
<form name ="frm" action="return form_depth1(this)" method="POST">
<label><input type="checkbox" id="fruit" name="fruit" value="사과">사과</label>
<label><input type="checkbox" id="fruit" name="fruit" value="딸기">딸기</label>
<label> <input type="checkbox" id="fruit" name="fruit" value="바나나">바나나</label>
<label><input type="checkbox" id="color" name="color" value="노랑">노랑</label>
<label><input type="checkbox" id="color" name="color" value="파랑">파랑</label>
<label><input type="checkbox" id="color" name="color" value="빨강">빨강</label>
<input type="submit" name="submit" value="전송">
</form>
--제이쿼리--
//form_submit
function form_depth1(f){
fruit_group="";
$("input[name=fruit]:checked").each(function() {
fruit_group+= $(this).val()+",";
});
f.fruit.value = fruit_group;
color_group="";
$("input[name=color]:checked").each(function() {
color_group+= $(this).val()+",";
});
f.color.value = color_group;
f.action = "/form_result.php";
}
--출력---
<?php
$fruit= $_POST['fruit'];
$color= $_POST['color'];
echo $fruit;
echo $color;
?>
이렇게해서 넘겼는데
fruit_group를 alert 띄우면 다 넘어가는데
f.fruit.value이게 안먹는것 같아요,,,
무슨 문제가 있을까요..ㅠ?
답변 2
인풋 name=fruit 가 이미 사용되고 있어서 입니다.
<input type="hidden" name="post_fruit">
<input type="hidden" name="post_color">
이렇게 히든값을 주고시 자바스크립트에서
f.post_fruit.value = fruit_group;
f.post_color.value = color_group;
이렇게 넘겨주시고
php에서
$fruit= $_POST['post_fruit'];
$color= $_POST['post_color'];
이렇게 받아보세요.
채택된 답변 처럼했으면 안될텐데 ㅎㅎㅎ
다음을 참조해 보시죠.
<form name ="frm" method="POST" onsubmit="return form_depth1(this);">
<input type="hidden" name="fruit_val" value="">
<label><input type="checkbox" id="fruit0" name="fruit[]" value="사과">사과</label>
<label><input type="checkbox" id="fruit1" name="fruit[]" value="딸기">딸기</label>
<label> <input type="checkbox" id="fruit2" name="fruit[]" value="바나나">바나나</label>
<input type="hidden" name="color_val" value="">
<label><input type="checkbox" id="color0" name="color[]" value="노랑">노랑</label>
<label><input type="checkbox" id="color1" name="color[]" value="파랑">파랑</label>
<label><input type="checkbox" id="color2" name="color[]" value="빨강">빨강</label>
<input type="submit" name="submit" value="전송">
</form>
<script>
//form_submit
function form_depth1(f){
fruit_group="";
$("input[name='fruit[]']:checked").each(function() {
fruit_group += $(this).val()+",";
});
f.fruit_val.value = fruit_group;
alert(f.fruit_val.value);
color_group="";
$("input[name='color[]']:checked").each(function() {
color_group += $(this).val()+",";
});
f.color_val.value = color_group;
alert(f.color_val.value);
f.action = "/form_result.php";
}
</script>
답변을 작성하시기 전에 로그인 해주세요.