论坛首页 入门技术论坛

将3个列表中的值选中并添加到另一个select1中,然后将select1中的内容提交到后台

浏览 2005 次
该帖已经被评为新手帖
作者 正文
   发表时间:2009-02-26   最后修改:2010-12-05
<select id="hereFirstClass" name="hereFirstClass" style="width:130"
									size="8" onchange="testName(1,this);">
									
										<option value="2">食品、饮料</option>
									
										<option value="3">服装</option>
									
										<option value="4">纺织、皮革</option>
									
										<option value="5">电工电气</option>
									
										<option value="6">家用电器</option>
									
										<option value="7">数码、电脑</option>
									
										<option value="8">化工</option>
									
										<option value="9">冶金矿产</option>
									
										<option value="10">能源</option>
									
										<option value="11">环保</option>
									
										<option value="12">交通运输</option>
									
										<option value="13">建筑、建材</option>
									
										<option value="14">机械及行业设备</option>
									
										<option value="15">家居用品</option>
									
										<option value="16">医药、保养</option>
									
										<option value="17">礼品、工艺品、饰品</option>
									
										<option value="18">运动、休闲</option>
									
										<option value="21">办公、文教</option>
									
										<option value="23">包装</option>
									
										<option value="30">安全、防护</option>
									
										<option value="32">库存积压</option>
									
										<option value="33">汽摩及配件</option>
									
										<option value="34">印刷</option>
									
										<option value="52">纸业</option>
									
										<option value="53">传媒、广电</option>
									
										<option value="54">服饰</option>
									
										<option value="55">橡塑</option>
									
										<option value="56">精细化学品</option>
									
										<option value="57">电子元器件</option>
									
										<option value="58">照明工业</option>
									
										<option value="59">五金、工具</option>
									
										<option value="509">通信产品</option>
									
										<option value="1813">玩具</option>
									
										<option value="2829">二手设备转让</option>
									
										<option value="10208">仪器仪表</option>
									
									
								</select>

								<select id="hereSecondClass" name="hereSecondClass" style="width:130"
									size="8" onchange="testName(2,this);">
								</select>

								<select id="hereThirdClass" name="hereSecondClass" style="width:130"
									size="8" onchange="testName(3,this);">
								</select>
								<div class="add_Delete"><input type="button" value="↓填加" onclick="addline()"/>
      <input type="button" value="x 删除" onclick="delline()"/></div>
      <script type="text/javascript" >
      	function addline() {
      		var num = document.getElementById("select1");
      		if(num.length>5) {
      			alert("最多只能添加6行");
      			return false;
      		}
      		var obj;
      		obj = document.createElement("option");
      		
      		var obj1 = document.getElementById("hereFirstClass");
      		var obj2 = document.getElementById("hereSecondClass");
      		var obj3 = document.getElementById("hereThirdClass");
      		if(document.getElementById("hereFirstClass").value=="") {
      			alert("请选择主营行业");
      			return false;
      		}
      		var hereFirstValue = document.getElementById("hereFirstClass").value;
			var hereFirstName = document.getElementById("hereFirstClass").options[obj1.selectedIndex].text;
      		
      		if(document.getElementById("hereSecondClass").value=="") {
      			obj.value = hereFirstValue;
      			obj.text = hereFirstName;
      			document.getElementById("select1").add(obj);
      		}else if(document.getElementById("hereThirdClass").value=="") {
      			var hereSecondValue = document.getElementById("hereSecondClass").value;
      			var hereSecondName = document.getElementById("hereSecondClass").options[obj2.selectedIndex].text;
      			obj.value = hereFirstValue+"//"+hereSecondValue;
      			obj.text = hereFirstName+"//"+hereSecondName;
      			document.getElementById("select1").add(obj);
      		}else{
      			var hereThirdValue = document.getElementById("hereThirdClass").value;
      			var hereThirdName = document.getElementById("hereThirdClass").options[obj3.selectedIndex].text;
      			var hereSecondValue = document.getElementById("hereSecondClass").value;
      			var hereSecondName = document.getElementById("hereSecondClass").options[obj2.selectedIndex].text;
      			obj.value = hereFirstValue+"//"+hereSecondValue+"//"+hereThirdValue;
      			obj.text = hereFirstName+"//"+hereSecondName+"//"+hereThirdName;
      			document.getElementById("select1").add(obj);
      		}
      		
      	}
      	
      	function delline() {
      		document.all.select1.options.remove(document.all.select1.selectedIndex);
      		document.all.select1.selectIndex=0;
      	}
      
      </script>
      
    <table width="460" name="table3" id="table3" >
   		<select size="8" name="select1" id="select1" multiple="true">
   		</select>
    </table>

//------------------------提交时的javascript
<script type="text/javascript">
	function refer() {
		var op = document.getElementById("select1").getElementsByTagName("option");
		if(op.length<0) {
			alert("请选择主营行业");
			return false;
		}else {
			for(var i=0; i<op.length; i++) {
				var str = "input"+i; 
				document.getElementById(str).value = op[i].childNodes[0].nodeValue;
			}
		}
		document.form1.action="/HereB2B/corporate?method=insertCorporate";
		document.form1.submit();
	}
</script>
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics