admin管理员组文章数量:1025270
I want to submit form by checkbox checked without redirecting/reloading/refreshing to another page but still on the same page.
and my targets:
after checkbox checked submit form with silent and then hiding
<div id="question1"><!--the form here--></div>
and show sections of
<div id="question2" style="<?php echo ($agree) ? 'display:block;' : 'display:none;' ?>"><!--some fields here--></div>
existing cases: I have the form as following that seem won't work,
<div id="question1">
<form action="<?php echo $submit); ?>" method="post" id="question" onsubmit="processForm();return false;">
<!--some rows here -->
<?php if ($quote['id'] == $color || !$color) { ?>
<?php $color = $quote['id']; ?>
<input type="radio" name="prefer_color" value="<?php echo $quote['id']; ?>" id="<?php echo $quote['id']; ?>" checked="checked" style="margin: 0px;" />
<?php } else { ?>
<input type="radio" name="prefer_color" value="<?php echo $quote['id']; ?>" id="<?php echo $quote['id']; ?>" style="margin: 0px;" />
<?php } ?>
<?php foreach ($prefer_places as $prefer_place) { ?>
<tr>
<td width="1">
<?php if ($prefer_place['id'] == $place || !$place) { ?>
<?php $place= $prefer_place['id']; ?>
<input type="radio" name="prefer_place" value="<?php echo $prefer_place['id']; ?>" id="<?php echo $prefer_place['id']; ?>" checked="checked" style="margin: 0px;" />
<?php } else { ?>
<input type="radio" name="prefer_place" value="<?php echo $prefer_place['id']; ?>" id="<?php echo $prefer_place['id']; ?>" style="margin: 0px;" />
<?php } ?></td>
</tr>
<?php } ?>
<?php if ($agree) { ?>
<input type="checkbox" name="agree" value="1" checked="checked" onchange="if(this.checked) this.form.processForm() ? $('#question2').css('display','block') : $('#question2').css('display','none');" id="agree" /><label for="agree">Agree</label>
<?php } else { ?>
<input type="checkbox" name="agree" value="1" onclick="if(this.checked) this.form.processForm() ? $('#question2').css('display','block') : $('#question2').css('display','none');" id="agree" /><label for="agree">Agree</label>
<?php } ?>
</form>
</div>
<div id="question2" style="<?php echo ($agree) ? 'display:block;' : 'display:none;' ?>">
<!--some fields here-->
</div>
with that code, after checkbox checked the form submitted but and redirecting to another page.
I need some help and pointers that I would be appreciated.
Thank a lot.
Updated,
By following your Instructions with use Ajax to handling this, so i try it as Ajax looks:
<script type="text/javascript">
function processForm() {
$.ajax( {
type: 'POST',
url: 'index.php?p=form/questions_steps',
data: 'prefer_color=' + encodeURIComponent(document.getElementById('input[name=\'<?php echo $quote['id']; ?>\']:checked').value) ? document.getElementById('input[name=\'<?php echo $quote['id']; ?>\']:checked').value : '') + '&prefer_color=' + encodeURIComponent(document.getElementById('input[name=\'<?php echo $prefer_color['id']; ?>\']:checked').value) ? document.getElementById('input[name=\'<?php echo $prefer_color['id']; ?>\']:checked').value : '') + '&ment=' + encodeURIComponent(document.getElementById('textarea=[name=\'ment\']').value) + '&agree=' + encodeURIComponent(document.getElementById('input[name=\'agree\']:checked').value) ? document.getElementById('input[name=\'agree\']:checked').value : ''),
success: function(data) {
$('#message').html(data);
}
} );
}
</script>
I want to submit form by checkbox checked without redirecting/reloading/refreshing to another page but still on the same page.
and my targets:
after checkbox checked submit form with silent and then hiding
<div id="question1"><!--the form here--></div>
and show sections of
<div id="question2" style="<?php echo ($agree) ? 'display:block;' : 'display:none;' ?>"><!--some fields here--></div>
existing cases: I have the form as following that seem won't work,
<div id="question1">
<form action="<?php echo $submit); ?>" method="post" id="question" onsubmit="processForm();return false;">
<!--some rows here -->
<?php if ($quote['id'] == $color || !$color) { ?>
<?php $color = $quote['id']; ?>
<input type="radio" name="prefer_color" value="<?php echo $quote['id']; ?>" id="<?php echo $quote['id']; ?>" checked="checked" style="margin: 0px;" />
<?php } else { ?>
<input type="radio" name="prefer_color" value="<?php echo $quote['id']; ?>" id="<?php echo $quote['id']; ?>" style="margin: 0px;" />
<?php } ?>
<?php foreach ($prefer_places as $prefer_place) { ?>
<tr>
<td width="1">
<?php if ($prefer_place['id'] == $place || !$place) { ?>
<?php $place= $prefer_place['id']; ?>
<input type="radio" name="prefer_place" value="<?php echo $prefer_place['id']; ?>" id="<?php echo $prefer_place['id']; ?>" checked="checked" style="margin: 0px;" />
<?php } else { ?>
<input type="radio" name="prefer_place" value="<?php echo $prefer_place['id']; ?>" id="<?php echo $prefer_place['id']; ?>" style="margin: 0px;" />
<?php } ?></td>
</tr>
<?php } ?>
<?php if ($agree) { ?>
<input type="checkbox" name="agree" value="1" checked="checked" onchange="if(this.checked) this.form.processForm() ? $('#question2').css('display','block') : $('#question2').css('display','none');" id="agree" /><label for="agree">Agree</label>
<?php } else { ?>
<input type="checkbox" name="agree" value="1" onclick="if(this.checked) this.form.processForm() ? $('#question2').css('display','block') : $('#question2').css('display','none');" id="agree" /><label for="agree">Agree</label>
<?php } ?>
</form>
</div>
<div id="question2" style="<?php echo ($agree) ? 'display:block;' : 'display:none;' ?>">
<!--some fields here-->
</div>
with that code, after checkbox checked the form submitted but and redirecting to another page.
I need some help and pointers that I would be appreciated.
Thank a lot.
Updated,
By following your Instructions with use Ajax to handling this, so i try it as Ajax looks:
<script type="text/javascript">
function processForm() {
$.ajax( {
type: 'POST',
url: 'index.php?p=form/questions_steps',
data: 'prefer_color=' + encodeURIComponent(document.getElementById('input[name=\'<?php echo $quote['id']; ?>\']:checked').value) ? document.getElementById('input[name=\'<?php echo $quote['id']; ?>\']:checked').value : '') + '&prefer_color=' + encodeURIComponent(document.getElementById('input[name=\'<?php echo $prefer_color['id']; ?>\']:checked').value) ? document.getElementById('input[name=\'<?php echo $prefer_color['id']; ?>\']:checked').value : '') + '&ment=' + encodeURIComponent(document.getElementById('textarea=[name=\'ment\']').value) + '&agree=' + encodeURIComponent(document.getElementById('input[name=\'agree\']:checked').value) ? document.getElementById('input[name=\'agree\']:checked').value : ''),
success: function(data) {
$('#message').html(data);
}
} );
}
</script>
Share
Improve this question
edited Nov 29, 2010 at 7:11
jones
asked Nov 29, 2010 at 5:43
jonesjones
6613 gold badges9 silver badges21 bronze badges
3 Answers
Reset to default 3As your requirement you have to use AJAX for submitting form without refreshing page. this is very easiest way for submit form in silent mode.
Thanks.
You can use the ajax JQuery function, for example:
$.ajax({
url: "page.php",
type: "GET",
data: (id : "123")
});
You can send data to the server w/o anything happening on the page.
Use Jquery. It's fast and easy.
IF no database interaction required then simply use javascrit.
I want to submit form by checkbox checked without redirecting/reloading/refreshing to another page but still on the same page.
and my targets:
after checkbox checked submit form with silent and then hiding
<div id="question1"><!--the form here--></div>
and show sections of
<div id="question2" style="<?php echo ($agree) ? 'display:block;' : 'display:none;' ?>"><!--some fields here--></div>
existing cases: I have the form as following that seem won't work,
<div id="question1">
<form action="<?php echo $submit); ?>" method="post" id="question" onsubmit="processForm();return false;">
<!--some rows here -->
<?php if ($quote['id'] == $color || !$color) { ?>
<?php $color = $quote['id']; ?>
<input type="radio" name="prefer_color" value="<?php echo $quote['id']; ?>" id="<?php echo $quote['id']; ?>" checked="checked" style="margin: 0px;" />
<?php } else { ?>
<input type="radio" name="prefer_color" value="<?php echo $quote['id']; ?>" id="<?php echo $quote['id']; ?>" style="margin: 0px;" />
<?php } ?>
<?php foreach ($prefer_places as $prefer_place) { ?>
<tr>
<td width="1">
<?php if ($prefer_place['id'] == $place || !$place) { ?>
<?php $place= $prefer_place['id']; ?>
<input type="radio" name="prefer_place" value="<?php echo $prefer_place['id']; ?>" id="<?php echo $prefer_place['id']; ?>" checked="checked" style="margin: 0px;" />
<?php } else { ?>
<input type="radio" name="prefer_place" value="<?php echo $prefer_place['id']; ?>" id="<?php echo $prefer_place['id']; ?>" style="margin: 0px;" />
<?php } ?></td>
</tr>
<?php } ?>
<?php if ($agree) { ?>
<input type="checkbox" name="agree" value="1" checked="checked" onchange="if(this.checked) this.form.processForm() ? $('#question2').css('display','block') : $('#question2').css('display','none');" id="agree" /><label for="agree">Agree</label>
<?php } else { ?>
<input type="checkbox" name="agree" value="1" onclick="if(this.checked) this.form.processForm() ? $('#question2').css('display','block') : $('#question2').css('display','none');" id="agree" /><label for="agree">Agree</label>
<?php } ?>
</form>
</div>
<div id="question2" style="<?php echo ($agree) ? 'display:block;' : 'display:none;' ?>">
<!--some fields here-->
</div>
with that code, after checkbox checked the form submitted but and redirecting to another page.
I need some help and pointers that I would be appreciated.
Thank a lot.
Updated,
By following your Instructions with use Ajax to handling this, so i try it as Ajax looks:
<script type="text/javascript">
function processForm() {
$.ajax( {
type: 'POST',
url: 'index.php?p=form/questions_steps',
data: 'prefer_color=' + encodeURIComponent(document.getElementById('input[name=\'<?php echo $quote['id']; ?>\']:checked').value) ? document.getElementById('input[name=\'<?php echo $quote['id']; ?>\']:checked').value : '') + '&prefer_color=' + encodeURIComponent(document.getElementById('input[name=\'<?php echo $prefer_color['id']; ?>\']:checked').value) ? document.getElementById('input[name=\'<?php echo $prefer_color['id']; ?>\']:checked').value : '') + '&ment=' + encodeURIComponent(document.getElementById('textarea=[name=\'ment\']').value) + '&agree=' + encodeURIComponent(document.getElementById('input[name=\'agree\']:checked').value) ? document.getElementById('input[name=\'agree\']:checked').value : ''),
success: function(data) {
$('#message').html(data);
}
} );
}
</script>
I want to submit form by checkbox checked without redirecting/reloading/refreshing to another page but still on the same page.
and my targets:
after checkbox checked submit form with silent and then hiding
<div id="question1"><!--the form here--></div>
and show sections of
<div id="question2" style="<?php echo ($agree) ? 'display:block;' : 'display:none;' ?>"><!--some fields here--></div>
existing cases: I have the form as following that seem won't work,
<div id="question1">
<form action="<?php echo $submit); ?>" method="post" id="question" onsubmit="processForm();return false;">
<!--some rows here -->
<?php if ($quote['id'] == $color || !$color) { ?>
<?php $color = $quote['id']; ?>
<input type="radio" name="prefer_color" value="<?php echo $quote['id']; ?>" id="<?php echo $quote['id']; ?>" checked="checked" style="margin: 0px;" />
<?php } else { ?>
<input type="radio" name="prefer_color" value="<?php echo $quote['id']; ?>" id="<?php echo $quote['id']; ?>" style="margin: 0px;" />
<?php } ?>
<?php foreach ($prefer_places as $prefer_place) { ?>
<tr>
<td width="1">
<?php if ($prefer_place['id'] == $place || !$place) { ?>
<?php $place= $prefer_place['id']; ?>
<input type="radio" name="prefer_place" value="<?php echo $prefer_place['id']; ?>" id="<?php echo $prefer_place['id']; ?>" checked="checked" style="margin: 0px;" />
<?php } else { ?>
<input type="radio" name="prefer_place" value="<?php echo $prefer_place['id']; ?>" id="<?php echo $prefer_place['id']; ?>" style="margin: 0px;" />
<?php } ?></td>
</tr>
<?php } ?>
<?php if ($agree) { ?>
<input type="checkbox" name="agree" value="1" checked="checked" onchange="if(this.checked) this.form.processForm() ? $('#question2').css('display','block') : $('#question2').css('display','none');" id="agree" /><label for="agree">Agree</label>
<?php } else { ?>
<input type="checkbox" name="agree" value="1" onclick="if(this.checked) this.form.processForm() ? $('#question2').css('display','block') : $('#question2').css('display','none');" id="agree" /><label for="agree">Agree</label>
<?php } ?>
</form>
</div>
<div id="question2" style="<?php echo ($agree) ? 'display:block;' : 'display:none;' ?>">
<!--some fields here-->
</div>
with that code, after checkbox checked the form submitted but and redirecting to another page.
I need some help and pointers that I would be appreciated.
Thank a lot.
Updated,
By following your Instructions with use Ajax to handling this, so i try it as Ajax looks:
<script type="text/javascript">
function processForm() {
$.ajax( {
type: 'POST',
url: 'index.php?p=form/questions_steps',
data: 'prefer_color=' + encodeURIComponent(document.getElementById('input[name=\'<?php echo $quote['id']; ?>\']:checked').value) ? document.getElementById('input[name=\'<?php echo $quote['id']; ?>\']:checked').value : '') + '&prefer_color=' + encodeURIComponent(document.getElementById('input[name=\'<?php echo $prefer_color['id']; ?>\']:checked').value) ? document.getElementById('input[name=\'<?php echo $prefer_color['id']; ?>\']:checked').value : '') + '&ment=' + encodeURIComponent(document.getElementById('textarea=[name=\'ment\']').value) + '&agree=' + encodeURIComponent(document.getElementById('input[name=\'agree\']:checked').value) ? document.getElementById('input[name=\'agree\']:checked').value : ''),
success: function(data) {
$('#message').html(data);
}
} );
}
</script>
Share
Improve this question
edited Nov 29, 2010 at 7:11
jones
asked Nov 29, 2010 at 5:43
jonesjones
6613 gold badges9 silver badges21 bronze badges
3 Answers
Reset to default 3As your requirement you have to use AJAX for submitting form without refreshing page. this is very easiest way for submit form in silent mode.
Thanks.
You can use the ajax JQuery function, for example:
$.ajax({
url: "page.php",
type: "GET",
data: (id : "123")
});
You can send data to the server w/o anything happening on the page.
Use Jquery. It's fast and easy.
IF no database interaction required then simply use javascrit.
本文标签: phpsubmit form with checkbox without refreshing pageStack Overflow
版权声明:本文标题:php - submit form with checkbox without refreshing page - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745620846a2159561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论