html - Display tab contents - Javascript -


i working js function have tabbed panel , each tab opens division within same html file. i've set first tab's displayed default(these contents active page loads). when try clicking second tab specified tab's contents don't displayed.

html forms displayed under each tab

first tab's contents under division addrequest division

<div id="addrequest" class="tabcontent">  <div id="form_container">  <!--<h1><a>acquisition</a></h1>--> <form id="form_1147240" class="appnitro"  method="post" action="">     <div class="form_description">         <h2>acquisition</h2>         <p>enter details of material required</p>     </div>     <ul >          <div id="leftdiv" style="float: left; width: 50%;" >              <!--material type-->              <li id="li_7" >                 <label class="description" for="element_7">material type </label>                 <div class = "listitems">                     <select class="element select medium" id="element_7" name="element_7">                         <option value="" selected="selected"></option>                         <option value="1" >books</option>                         ... 

tab 1 contents

second tab's contents under division addnewmaterial division

<div id="addnewmaterial" class="tabcontent">     <div id="form_container1">         <form id="form_11472401" class="appnitro"  method="post" action="">             <div class="form_description">                 <h2>acquisition</h2>                 <p>enter details of new material</p>             </div>             <ul >                  <div id="leftdiv1" style="float: left; width: 50%;" >                      <!--material type-->                      <li id="li_71" >                         <label class="description" for="element_71">material type </label>                         <div class = "listitems">                             <select class="element select medium" id="element_71" name="element_71">                                 <option value="" selected="selected"></option>                                 <option value="1" >books</option> 

contents not displayed tab 2

tab section

<body>  <ul class="tab">     <li><a href="#" class="tablinks" onclick="opentab(event, 'addrequest')">add request</a></li>     <li><a href="#" class="tablinks" onclick="opentab(event, 'addnewmaterial')">new materials</a></li>  </ul> <div id="addrequest" class="tabcontent"> <div id="form_container"> 

js function

function opentab(evt, divisionid) { // declare variables var i, tabcontent, tablinks;  // elements class="tabcontent" , hide them tabcontent = document.getelementsbyclassname("tabcontent"); (i = 0; < tabcontent.length; i++) {     tabcontent[i].style.display = "none"; }  // elements class="tablinks" , remove class "active" tablinks = document.getelementsbyclassname("tablinks"); (i = 0; < tablinks.length; i++) {     tablinks[i].classname = tablinks[i].classname.replace(" active", ""); }  // show current tab, , add "active" class link opened tab document.getelementbyid(divisionid).style.display = "block"; evt.currenttarget.classname += " active"; } 

try put below code in java-script code. trying create jsfiddle using code. sorry bad formating in jsfiddle, can see output window working fine. check out fiddle

document.getelementbyid('addrequest').style.display = "block"; document.getelementbyid('addnewmaterial').style.display = "none"; 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -