<html>
<head>
<title>Upload Form</title>
<head>
<link href="<?php echo base_url()?>/assets/validationEngine.jquery.css?1" rel="tex/css">
<script type="text/javascript" src="<?php echo base_url()?>/assets/jquery-1.6.min.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>/assets/jquery.validationEngine.js?1"></script>
<script type="text/javascript" src="<?php echo base_url()?>/assets/jquery.validationEngine-en.js?1"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#myForm").submit(function(){
$("#myForm").validationEngine();
var groupSubject = $.trim($("#groupSubject").val());
if(event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
if(groupSubject == ""){
alert("Please enter Group Subject Name");
$("#groupSubject").focus();
return false;
}
var practical = 0;
var isChecked = $("#practical:checked").length;
if (isChecked == 1)
practical = 1;
else
practical = 0;
var baseUrl = $("#base_url").val();
var str = $("form").serialize();
$.ajax({
url: baseUrl+'login/saveGroupSubject',
type:'post',
data: str,
success:function(data){
alert(data);
getSubjectList();
$("#groupSubject").focus();
}
});
});
//getSubjectList();
$(".showdata").change(function(){
var batchId = $("#batch").val();
var courseId = $("#course").val();
if(batchId != "" && courseId !=""){
getSubjectList();
}
});
}); // Ready Function
function getSubjectList(){
var batchId = $("#batch").val();
var courseId = $("#course").val();
var baseUrl = $("#base_url").val();
if(event.preventDefault)
{
event.preventDefault();
}
else
{
event.returnValue = false;
}
var str = "batchId="+batchId+"&courseId="+courseId
$.ajax({
url: baseUrl+'login/getGroupSubjectList',
type:'post',
data: str,
success:function(data){
//alert(data);
$(".groupSubjectList").html(data);
}
});
}
function addOption(a, b, e) {
var d = new Option(b, e);
var c = a.length;
a.options[c] = d
}
function deleteOption(a, c) {
var b = a.length;
if (b > 0) {
a.options[c] = null
}
}
function moveOptions(f, c) {
var e = f.length;
var g = new Array();
var a = new Array();
var b = 0;
var d;
for (d = e - 1; d >= 0; d--) {
if (f.options[d].selected) {
g[b] = f.options[d].text;
a[b] = f.options[d].value;
deleteOption(f, d);
b++
}
}
for (d = b - 1; d >= 0; d--) {
addOption(c, g[d], a[d])
}
return false
}
function hasOptions(a) {
if (a != null && a.options != null) {
return true
}
return false
}
function swapOptions(f, e, c) {
var h = f.options;
var b = h[e].selected;
var d = h[c].selected;
var a = new Option(h[e].text, h[e].value, h[e].defaultSelected, h[e].selected);
var g = new Option(h[c].text, h[c].value, h[c].defaultSelected, h[c].selected);
h[e] = g;
h[c] = a;
h[e].selected = d;
h[c].selected = b
}
function moveOptionUp(a) {
if (!hasOptions(a)) {
return false
}
for (i = 0; i < a.options.length; i++) {
if (a.options[i].selected) {
if (i != 0 && !a.options[i - 1].selected) {
swapOptions(a, i, i - 1);
a.options[i - 1].selected = true
}
}
}
return false
}
function moveOptionTop(b) {
if (!hasOptions(b)) {
return false
}
var a = getSelectedLength(b);
if (a > 1) {
alert("You can move a single element to top.");
return false
}
for (i = 0; i < b.options.length; i++) {
if (i > 0 && i <= b.options.length && b.options[i].selected) {
var c = i;
while (c > 0) {
swapOptions(b, c, --c)
}
}
}
return false
}
function moveOptionDown(a) {
if (!hasOptions(a)) {
return false
}
for (i = a.options.length - 1; i >= 0; i--) {
if (a.options[i].selected) {
if (i != (a.options.length - 1) && !a.options[i + 1].selected) {
swapOptions(a, i, i + 1);
a.options[i + 1].selected = true
}
}
}
return false
}
function moveOptionBottom(b) {
if (!hasOptions(b)) {
return false
}
var a = getSelectedLength(b);
if (a > 1) {
alert("You can move a single element to bottom.");
return false
}
for (i = 0; i < b.options.length; i++) {
if (i >= 0 && i < b.options.length && b.options[i].selected) {
var c = i;
while (c < (b.options.length - 1)) {
swapOptions(b, c, ++c)
}
}
}
return false
}
function getSelectedLength(b) {
var a = 0;
for (i = 0; i < b.options.length; i++) {
if (b.options[i].selected) {
a++
}
}
return a
};
</script>
<style type="text/css">
li{margin: 0;
padding: 0;
list-style: none;
}
</style>
</head>
<body>
<table><form name="myForm" id="myForm" method="POST">
<tr><td>Course</td><td>
<select style="width:250px;" name="children[]" multiple="multiple" size="5" class="showdata validate[required]" id="children">
<?php
for($m =0; $m<count($course); $m++){?>
<option value="<?php echo $course[$m]['c_id'];?>"><?php echo $course[$m]['c_name'];?></option>
<?php }?>
</select>
</td>
<td><ul>
<li title="Move to Top" class="ui-state-default ui-corner-all" onclick="return moveOptionTop(document.getElementById('children'));"><span class="ui-icon ui-icon-arrowthickstop-1-n">Move Top</span></li>
<li> </li>
<li title="Move Up" class="ui-state-default ui-corner-all" onclick="return moveOptionUp(document.getElementById('children'));"><span class="ui-icon ui-icon-carat-1-n">Top</span></li>
<li> </li>
<li> </li>
<li title="Move Down" class="ui-state-default ui-corner-all" onclick="return moveOptionDown(document.getElementById('children'));"><span class="ui-icon ui-icon-carat-1-s">Bottom</span></li>
<li> </li>
<li title="Move to Bottom" class="ui-state-default ui-corner-all" onclick="return moveOptionBottom(document.getElementById('children'));"><span class="ui-icon ui-icon-arrowthickstop-1-s">Move Bottom</span></li>
</ul></td>
</tr>
</form>
</table>
<div class="groupSubjectList"></div>
</body>
</html>
設置選擇標籤到要選擇的值的值。 – Shahe
你可以通過javascript(jquery)來實現。 –