这是我的php表单,我想从页面加载的选定值上提交它的可能性。在页面加载时,我想选择Architect作为选定值。
<select name="with" <?php if(isset($_REQUEST['market']) && !empty($_REQUEST['market'])) { ?> onChange="if(this.value=='1'){window.location='?market=<?php echo $_REQUEST['market']; ?>&with=1'} else if(this.value=='2') {window.location='?market=<?php echo $_REQUEST['market']; ?>&with=2'} else {window.location='<?php echo $baseUrl."viewMeetings.php?market=".$_REQUEST['market']; ?>'}; <?php } else { ?> onChange=" if(this.value=='1'){window.location='?with=1'} else
if(this.value=='2') {window.location='?with=2'} else {window.location='<?php echo $baseUrl."viewMeetings.php"; ?>'}; <?php } ?>">
<option value="" <?php if(!isset($_REQUEST['with'])) { echo "selected=selected"; } ?>>ALL </option>
<option value="1" <?php if(isset($_REQUEST['with'])) { if($_REQUEST['with']==1) { echo "selected=selected"; } } ?>>Customer</option>
<option value="2" <?php if(isset($_REQUEST['with'])) { if($_REQUEST['with']==2) { echo "selected=selected"; } } ?> >Architect</option>
</select>
答案 0 :(得分:1)
尽量不要使用内联javascript。我不是Javascripting最好的,但看看这是否有效。您的描述不是很清楚,所以希望这是您正在寻找的!装载等在技术上有效,但它是否像你期望的那样工作是另一个故事:
jQuery Libraries
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
选择按钮(添加ID)
<select name="with" id="with-it">
<option value="" <?php if(!isset($_REQUEST['with'])) { echo "selected=selected"; } ?>>ALL </option>
<option value="1" <?php if(isset($_REQUEST['with'])) { if($_REQUEST['with']==1) { echo "selected=selected"; } } ?>>Customer</option>
<option value="2" <?php if(isset($_REQUEST['with'])) { if($_REQUEST['with']==2) { echo "selected=selected"; } } ?> >Architect</option>
</select>
onChange的脚本
<script>
$("#with-it").change(function() {
var ValueSet = $(this).val();
<?php if(isset($_REQUEST['market'])) { ?>
if(ValueSet == '1') {
window.location='?market=<?php echo $_REQUEST['market']; ?>&with='+ValueSet
}
else if(ValueSet == '2') {
window.location='?market=<?php echo $_REQUEST['market']; ?>&with='+ValueSet
}
else {
window.location='<?php echo $baseUrl."viewMeetings.php?market=".$_REQUEST['market']; ?>'}
<?php }
else { ?>
if(ValueSet == '1'){
window.location='?with=1';
}
else if(ValueSet =='2') {
window.location = '?with=2';
}
else {
window.location = '<?php echo $baseUrl."viewMeetings.php"; ?>';
}
<?php } ?>
});
</script>