js to obtain the drop-down list to select the value and text (select), as well as access to radio buttons (radio) group and modify the selected value of
Advertisements
<html>
<head><title>Gets the drop-down list to select key values, and text (select)</title></head>
<body>
<script>
//Gets the drop-down list to select key text
function getSelectedText(name){
var obj=document.getElementById(name);
for(i=0;i<obj.length;i++){
if(obj[i].selected==true){
return obj[i].innerText; //The key is by option object the InnerText property gets the option text
}
}
}
//Gets the drop-down list to select key value
function getSelectedValue(name){
var obj=document.getElementById(name);
return obj.value; //So simple, the direct use of the object's value property to get to the
}
</script>
<select>
<option value="fist">1</option>
<option value="second">2</option>
<option value="third">3</option>
</select>
<input type="button" value="The selected text " />
<input type="button" value="The selected value " />
</body>
</html>
Second, access to radio buttons (radio) group and modify the selected value of
To see a lot of posts said js access the radio button (radio) group can be directly used the value of document.getElementById ( "oper"). Value, although the radio button group with the same drop-down list (list item is an array) is also an array in this way can be of value to the drop-down list, but the radio button group that they were less than the selected value. Under carefully studied, summarized as follows:
With different drop-down list, radio button or this.form.oper have to use document.getElementsByName ( 'oper') access to the array object, document.getElementById ( 'oper') Can not access to the array object (select can). But also to obtain the value of one cycle have to judge through acquisition, should not directly. Value (select can). And to change the radio button group to select items, but also have to change with each cycle of the radio button to determine the value.
Radio.html test code is as follows:
<html>
<head></head>
<script language="javascript">
//For the radio button's value for a single option and more options. Not selected return false; selecting the item and returns the value of an option.
function getRadio(oRadio){
var oRadioLength= oRadio.length;
var oRadioValue = false;
//alert("oRadioLength:["+oRadioLength+"]");
if (oRadioLength== undefined){
if (oRadio.checked){
oRadioValue = oRadio.value;
}
}else{
for (i=0;i<oRadioLength;i++){
//alert("oRadio["+i+"]:"+oRadio[i].checked+"/"+oRadio[i].value);
if (oRadio[i].checked){
oRadioValue = oRadio[i].value;
break;
}
}
}
return oRadioValue;
}
//Improvement:
//For the radio button's value, pass the name as a parameter to the radio. Not selected return false; selecting the item and returns the value of an option.
function getRadioValue(name){
var radioes = document.getElementsByName(name);
for(var i=0;i<radioes.length;i++)
{
if(radioes[i].checked){
return radioes[i].value;
}
}
return false;
}
//By value, modify the selected radio button
function changeRadio(oRadio,oRadioValue){ //Passing in an object
for(var i=0;i<oRadio.length;i++) //Loop
{
if(oRadio[i].value==oRadioValue) //To compare values
{
oRadio[i].checked=true; //Modify the selected
break; //Stop the loop
}
}
}
//Improvement:
//By value, modify the selected radio button
function setRadio(name,sRadioValue){ //Incoming radio of name and value of the selected item
var oRadio = document.getElementsByName(name);
for(var i=0;i<oRadio.length;i++) //Loop
{
if(oRadio[i].value==sRadioValue) //To compare values
{
oRadio[i].checked=true; //Modify the selected
break; //Stop the loop
}
}
}
</script>
<body>
<form name="frm">
<input type="radio" name="oper" value="agree" >Agree with </td>
<input type="radio" name="oper" value="downchange" checked>Under modify </td>
<input type="radio" name="oper" value="refuse">Declined </td>
<input type="radio" name="oper" value="report" >Escalation </td>
<br>
alert('result:'+getRadio(this.form.oper))
<input type="button" name="test1" value="Button 1 ">
<br>
alert('result:'+getRadio(document.getElementById('oper')))
<input type="button" name="test2" value="Button 2 ">
<br>
alert(this.form.oper.value)
<input type="button" name="test3" value="Button 3 ">
<br>
changeRadio(this.form.oper,"Escalation ")
<input type="button" name="test4" value="Button 4 ">
<br><br><br><br>
<select>
<option value="agree" >Agree with </option>
<option value="downchange" selected>Under modify </option>
<option value="refuse">Declined </option>
<option value="report">Escalation </option>
</select>
<br>
alert(this.form.slt.value)
<input type="button" name="test5" value="Button 5 ">
<br>
document.getElementById('slt')[2].innerText)
<input type="button" name="test6" value="Button 6 ""alert(document.getElementById('slt')[2].innerText);">
</form>
</body>
</html> Reprint Address:
Related Posts of js to obtain the drop-down list to select the value and text (select), as well as access to radio buttons (radio) group and modify the selected value of
-
Hibernate primary key strategy-sequence
Today, the use of hibernate in the company encountered a troublesome problem, the use of hibernate when the primary key generation strategy set sequence, but always reported in the implementation could not get next sequence value of the error, then o ...
-
hibernate call stored procedure
hibernate call stored procedure
-
hibernate using c3p0 connection pooling
Private http://www.lifevv.com/tenyo/doc/20070605102040991.html c3p0 for open source's JDBC connection pool, with the release hibernate. This article describes how to use the hibernate configuration in c3p0. c3p0 connection pool configuration is v ...
-
Hibernate configuration parameters hibernate.hbm2ddl.auto
Hibernate in the configuration file: <properties> <property name="hibernate.hbm2ddl.auto" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...
-
Build flex + spring + blazeds + hibernate application
Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...
-
Hibernate connection pool configuration
Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15
-
hibernate generic generic DAO
package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *
-
Struts2 + hibernate + spring problem user log in
dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q
-
Hibernate secondary cache
Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...
-
Hibernate's lazy strategy
hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...












