0

I want to display record of the selected month from drop down. I have a function for which a variable inside this function has to pick selected month from a different function.

I am using getElementById().value to read value from the other function. My application has 3 levels.

Level 1 is very generic, level 2 is classified and level 3 is very specific(further classified from level 2). I'll select month from level 1 and level 2, level 3 should display corresponding data. Level 2 works fine by reading getElementById("month").value from level 1 but level 3 is not reading getElementById("month").value from level 1. Below is my code

function level_1() {
  var cur_month = new Date.today().toString("MM");
  cur_month=cur_month.trim();
  var sel_month = "";
  try{
    sel_month=document.getElementById("month_ps").value;
    cur_month = sel_month;
  } catch(err){
    sel_month=cur_month;
  }

  var display = "<div style='color: ffff00'>Month: <select name='month_ps' id='month_ps' value= '"+cur_month+"' style='font-weight: bold' onChange='level_1()'>"; 
  var output = <input type='radio' name='level1' onClick='level2()'>
}

function level_2(){
  var cur_month = new Date.today().toString("MM");
  cur_month=cur_month.trim();
  var sel_month = "";
  try{
    sel_month=document.getElementById("month_ps").value;
    cur_month = sel_month;
  } catch(err){
    sel_month=cur_month;
  }
  var output = <input type='radio' name='level2' onClick='level3()'>
}

function level_3(){
  var cur_month = new Date.today().toString("MM");
  cur_month=cur_month.trim();
  var sel_month = "";
  try{
    sel_month=document.getElementById("month_ps").value;
    cur_month = sel_month;
  } catch(err){
    sel_month=cur_month;
  }
}
Albzi
  • 15,431
  • 6
  • 46
  • 63
Rishiban R
  • 103
  • 2
  • 14
  • Are you saying you have multiple elements with the same ID? (That won't work.) The code shown seems to create the element as a string of html but then that string isn't used. There's a syntax error on the line with the `output` variable. – nnnnnn May 04 '17 at 08:06
  • Possible duplicate of [Get selected value in dropdown list using JavaScript?](http://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript) – wf4 May 04 '17 at 08:06
  • what is the error its giving in the browser debugger? – sudo May 04 '17 at 08:08
  • Also all your Date code is broken, no such thing as Date.today(). Date.now() is the same as just doing a new Date() ..timestamps the current time. – Brunis May 04 '17 at 08:08
  • Add the html also .. and put it in a jsbin or plnkr so we can see the whole thing :) – Brunis May 04 '17 at 08:09

0 Answers0