admin管理员组文章数量:1317572
I try to make custom theme option, a switch select option can change $bannerchange value. but i cannot add/update value of $bannerchange, select option inside a form. working fine with submit button but come to onchange="this.form.submit()
the select option not changing.
<?php
if(isset($_POST['wphw_submit'])){
wphw_opt();
}
function wphw_opt(){
$bannerchange = $_POST['bannerchange'];
if( get_option('bannerchange') != $bannerchange) {
$chk = update_option( 'bannerchange', $bannerchange);
}
}?>
<form method="post" action="">
<select name="bannerchange" onchange="this.form.submit()">
<option value="page1"<?php if (get_option('bannerchange') == "page1") { echo " selected"; } ?>>Custom Departure</option>
<option value="page2"<?php if (get_option('bannerchange') == "page2") { echo " selected"; } ?>>Fixed Departure</option>
</select>
<input type="submit" name="wphw_submit" value="Save changes" class="button-primary" />
</form><?php
switch ($bannerchange) {
case 'page2':
break;
case 'page1':
break;
}
$bannerchange get always undefined. I can debug this problem with straight way? any help greatly appreciated.
I try to make custom theme option, a switch select option can change $bannerchange value. but i cannot add/update value of $bannerchange, select option inside a form. working fine with submit button but come to onchange="this.form.submit()
the select option not changing.
<?php
if(isset($_POST['wphw_submit'])){
wphw_opt();
}
function wphw_opt(){
$bannerchange = $_POST['bannerchange'];
if( get_option('bannerchange') != $bannerchange) {
$chk = update_option( 'bannerchange', $bannerchange);
}
}?>
<form method="post" action="">
<select name="bannerchange" onchange="this.form.submit()">
<option value="page1"<?php if (get_option('bannerchange') == "page1") { echo " selected"; } ?>>Custom Departure</option>
<option value="page2"<?php if (get_option('bannerchange') == "page2") { echo " selected"; } ?>>Fixed Departure</option>
</select>
<input type="submit" name="wphw_submit" value="Save changes" class="button-primary" />
</form><?php
switch ($bannerchange) {
case 'page2':
break;
case 'page1':
break;
}
$bannerchange get always undefined. I can debug this problem with straight way? any help greatly appreciated.
Share Improve this question edited Nov 1, 2020 at 17:03 Noufal Binu asked Oct 18, 2020 at 8:51 Noufal BinuNoufal Binu 2713 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 0I fixed myself we can submit a form by triggering submit button click event:
jQuery(document).ready(function() {
jQuery('#bannerchange').on('change', function() {
var $form = jQuery(this).closest('form');
$form.find('input[type=submit]').click();
});
});
本文标签: javascripton change form submit variable value not updating
版权声明:本文标题:javascript - on change form submit variable value not updating 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742020776a2414622.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<select name="wphw_submit"
into<select name="bannerchange"
. – Mayeenul Islam Commented Oct 19, 2020 at 2:45if(isset($_POST)) { var_dump($_POST['bannerchange']); exit(); }
? – Mayeenul Islam Commented Oct 19, 2020 at 6:29