我想为下拉选择设置一个默认值。
例如krik
值为('pt123', 'washington', 'rob case', 'rob', 'rob')
。我想根据val4设置选择,这是电话卡ID。
问题:从krik
到input hidden
的值正在运行..但是设置选中是失败的..当我设置警报时,显示该值未定义。 。
如何从隐藏字段中获取值以比较$sel
条件..
请帮助..我已经尝试了几天......这让我思索了好几天。
function krik(val1, val2,val3,val4,val5) {
var calID = val1;
var calLoc = val2;
var calCase = val3;
var calCar = val4;
var casecod = val5;
$("#formkes-dialog").dialog("open");
$('#formkes-dialog').dialog({
title: $('#formkes-dialog').prop('title') + calCar
});
$("#CallerId").val(calID);
$("#CrimeLocation").val(calLoc);
$("#CaseDesc").val(calCase);
$("#casecod").val(casecod);
}
<input type="hidden" name="casecod" id="casecod" />
<script type="text/javascript">
<!-- var mytextvalue = document.getElementById("casecod").value; -->
alert(document.getElementById('casecod').val);
</script>
<?php
$sel = $_GET['casecod'];
?>
<select name="CaseCode" id="CaseCode" >
<option >Pilih</option>
<option selected='<?php (($sel == "case1")?"selected":"") ?>' value="case1">Gaduh</option>
<option selected='<?php (($sel == "case2")?"selected":"") ?>' value="case2">Rompak</option>
<option selected='<?php (($sel == "case3)?"selected":"") ?>' value="case3">Kemalangan</option>
</select>
答案 0 :(得分:0)
首先在隐藏字段中指定值。
Eg:
<input type="hidden" name="casecod" id="casecod" value="demo_value" />
用以下内容替换js: -
Use '.value' instead of '.val'.
<script type="text/javascript">
<!-- var mytextvalue = document.getElementById("casecod").value; -->
alert(document.getElementById('casecod').value);
</script>
答案 1 :(得分:0)
检查
function krik(val1, val2,val3,val4,val5) {
var calID = val1;
var calLoc = val2;
var calCase = val3;
var calCar = val4;
var casecod = val5;
$("#formkes-dialog").dialog("open");
$('#formkes-dialog').dialog({
title: $('#formkes-dialog').prop('title') + calCar
});
$("#CallerId").val(calID);
$("#CrimeLocation").val(calLoc);
$("#CaseDesc").val(calCase);
$("#casecod").val(casecod);
}
&#13;
<input type="hidden" name="casecod" id="casecod" />
<script type="text/javascript">
<!-- var mytextvalue = document.getElementById("casecod").value; -->
alert(document.getElementById('casecod').value);
</script>
<?php
$sel = $_GET['casecod'];
?>
<select name="CaseCode" id="CaseCode" >
<option value="pilih" >Pilih</option>
<option selected='<?php (($sel == "case1")?"selected":"") ?>' value="case1">Gaduh</option>
<option selected='<?php (($sel == "case2")?"selected":"") ?>' value="case2">Rompak</option>
<option selected='<?php (($sel == "case3")?"selected":"") ?>' value="case3">Kemalangan</option>
</select>
&#13;
答案 2 :(得分:0)
同样更正选项From
<option selected='<?php (($sel == "case3)?"selected":"") ?>' value="case3">Kemalangan</option>
要
<option selected='<?php (($sel == "case3")?"selected":"") ?>' value="case3">Kemalangan</option>
然后检查。
答案 3 :(得分:0)
我juz得到了答案..这是juz becoz我在页面顶部声明查询以获取casecod数据.. :) ....谢谢所有.. juz一个简单的事情,但用得很难。 。
<?php
session_start();
require_once("includes/conn.php");
$sql_select = "SELECT * FROM report WHERE Status = '1'";
$result = mysql_query($sql_select);
$test = mysql_fetch_array($result);
$CaseCode =$test['CaseCode'];
?>
<select name="CaseCode" id="CaseCode">
<option>--choose one--</option>
<option selected="<?php (($CaseCode == "Kidnap" || $CaseCode == "kidnap")?'selected':'') ?>" value="Kidnap">Kidnapped</option>
<option selected="<?php (($CaseCode == "Robbery" || $CaseCode == "robbery")?'selected':'') ?>" value="Robbery">Robbery</option>
<option selected="<?php (($CaseCode == "Wilderness" || $CaseCode == "wilderness")?'selected':'') ?>" value="Wilderness">Wilderness</option>
</select>
&#13;