Search code examples
javascriptfunctionvariableschaining

Javascript variable as function name in chain


I am trying to pull a variable that is captured from a form element in to a function chain. The variable value needs to act as a function name. Example:

<form name="myform">
  <input type="radio" id="DayOfWeek" name="DayOfWeek" value="monday" />Monday
  <input type="radio" id="DayOfWeek" name="DayOfWeek" value="tuesday" />Tuesday
  <input type="radio" id="DayOfWeek" name="DayOfWeek" value="wednesday" />Wednesday
  <input type="radio" id="DayOfWeek" name="DayOfWeek" value="thursday" />Thursday
  <input type="radio" id="DayOfWeek" name="DayOfWeek" value="friday" />Friday
</form>

script:

var **monthday**=$("input[name='DayOfWeek']:checked").val();
NewDate = Date.parse(NewDate).add(1).month().**monthday**();

My problem has been getting the variable 'monthday' value to act as the function name in that chain. Am I having a 'duh' moment or is this not possible?


Solution

  • How about this:Date.parse(NewDate).add(1).month()[monthday]();?