html - Javascript getElementBy -


i have problem detect option selection instead of using getelementbyid want use getelementbyvalue.does exist?? code

     <script type="text/javascript">      var total;   function oneway(){  document.getelementbyid("return_date").style.visibility = "hidden";  document.getelementbyid("return_time").style.visibility = "hidden";  }  function return_way(){  document.getelementbyid("return_date").style.visibility = "visible";  document.getelementbyid("return_time").style.visibility = "visible";  }  function state_price(){ var way=document.getelementbyid("direction").value;  var placefrom = document.getelementbyid("state_from").value; var placeto   = document.getelementbyid("state_to").value;  if (direction == "oneway"){     if ((placefrom=="batu pahat" && placeto=="alor setar") ||(placefrom =="alor setar" && placeto=="batu pahat")){          total=55.00;         document.booking.total_price.value = total;       }else if ((placefrom=="batu pahat" && placeto=="bachok")||(placefrom=="bachok" && placeto=="batu pahat"))     {          total=60.00;         document.booking.total_price.value = total;        }else if ((placefrom=="batu pahat" && placeto=="a famosa") || (placefrom=="a famosa" && placeto=="batu pahat"))     {          total=65.50;         document.booking.total_price.value = total;      }else if ((placefrom=="batu pahat" && placeto=="bahau")||(placefrom=="bahau" && placeto=="batu pahat"))     {         total=70.00;         document.booking.total_price.value = total;      }else if ((placefrom=="batu pahat" && placeto=="bentong") ||(placefrom=="bentong" && placeto=="batu pahat"))     {         total=75.50;         document.booking.total_price.value = total;     }else if ((placefrom=="batu pahat" && placeto=="kubang kerian") ||(placefrom=="kubang kerian" && placeto=="batu pahat"))     {         total=80.00;         document.booking.total_price.value = total;      }      else     {          document.booking.txttotal.value = "fail";         window.alert("please enter different destination");      } } else {    ///something else  } } </script> 

and part of html coding

 <tr >   <td>travel direction:</td>  <td >   <input type="radio" name ="direction" value = "oneway"  onclick = "oneway()"/>one way  <input type="radio" name ="direction" value = "return"  onclick = "return_way()"/>return   </td>  </tr> 

i don't want use name i'm using in php coding.so don;t want use it.is there way can javascript mentioned above (getelementbyvalue)?thank in advance

well if can't set id attribute can apply css class , use:

document.getelementsbyclassname 

document.getelementsbyclassname (needs ie 9.0 or higher)

or can traverse whole dom checking value attribute. slow hell , bug-prone without using jquery or similar.

edit: quentin answer better, document.queryselector works on ie8 or higher , don't need create css classes.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -