SoFunction
Updated on 2025-02-28

JS method to change option attribute in select

This article describes how JS changes the option attribute in select. Share it for your reference. The details are as follows:

Help a friend solve a small problem. The requirement is to change the text value displayed in the selected tab, and the new value is stored in a text box.

Initial window:

<html>
 <head>
  <title>Original window</title>
  <script>
   var parentValue=""; //Global variables are used to save the value of the specified opeion in the select when clicking details   function detail() {
    var select=('SHGX'); //Get select object    parentValue=[].text; 
    ('Details window.html')
   }
   function updateSelect(childValue) {
    var select=('SHGX'); 
    for(var i=0;i<;i++) {
     if([i].text==parentValue) 
      [i].text=childValue;
    }    
   }
  </script>
 </head>
 <body>
  <select id='SHGX'>
   <option value='111' title='husband'>husband</option>
   <option value='112' title='wife'>wife</option>
   <option value='120' title='son'>son</option>
   <option value='121' title='only son'>独生son</option>
   <option value='122' title='Stepson'>继son</option>
   <option value='128' title='son in law'>son in law</option>   
  </select>
  <button onclick="detail(); ">Details</button>
 </body>
</html>

Details window:

<html>
 <head>
 <title>Details window</title>
 <script>
  function modify() {
  var childValue=('text_01').value;
  (childValue); //Calling the function of the parent window  }
 </script>
 </head>
 <body>
 <input  type="text" value=""/>
 <button onclick="modify();">Revise</button>
 </body>
</html>

I hope this article will be helpful to everyone's JavaScript programming.