<
script src = "js/jquery.js" ></ script ><
script type = "text/javascript" src = "js/editableList.js" ></ script >$(document).ready(
function () {$(
'#add' ).click( function () {$(
"#list" ).appendToList({value: 'addelementvalue' ,controllist: 'control_list' });});
$(
'#remove' ).click( function () {$(
'#list' ).removeFromList({selectboxid: 'control_list' });});
$(
'form' ).submit( function () { return false ;});
});
</
script ><
title > Editable Control List </ title ></
head ><
body bgcolor = "#CCCCCC" ><
form name = "f1" ><
div id = "list" ><
label > Editable Control List </ label >< br ><
table ><
tr ><
td ><
table ><
tr >< td >< select size = 6 id = "control_list" style =" width : 145px ;" ></ select ></ td ></ tr ><
tr >< td >< input type = "text" id = "addelementvalue" /></ td ></ tr ></
table >
</
td >
<
td ><
table ><
tr >< td >< input type = "image" src = "Images/remove.png" id = "remove" title = "click here to remove value from the list" alt = "click here to remove value from the list" style =" top : 300px " /></ td ></ tr ><
tr >< td >< input type = "image" src = "Images/add.png" alt = "click here to append value to list" title = "click here to append value to list" id = "add" /></ td ></ tr ></
table ></
td ></
tr >(
function ($) { // jQuery plugin definition$.fn.appendToList =
function (params) { this .each( function () { // express a single node as a jQuery object var $list=$( '#' +params.controllist+ '' ); var $value=$( '#' +params.value+ '' ).val(); var isThere=$list.find( 'option:contains(' +$value+ ')' ).val()==$value? true : false ; if ($value== '' ||$value== null ){
alert(
'Enter Value' );}
else if ($.trim($value)== "" ){
alert(
'Only spaces not allowed' );}
else if (isThere) {alert(
'Duplicates Not Allowed' );}
else{
$list.append(
"<option value='" +$value+ "' alt='" +$value+ "' title='" +$value+ "'>" +$value+ "</option>" );document.getElementById(params.value).value=
"" ;}
});
// allow jQuery chaining return this ;};