parameters wont passs via Javascript

parameters wont passs via Javascript

I am having trouble passing values via Javascript. 
APEX PAGE:
//STUFF HERE
First Goal:

Goal:
Second Goal:

Goal:
Third Goal:

Goal:
Strategy to Achieve Goal: Controller ...OTHER CODE AND CONSTRUCTOR.. Public Pagereference AddTask(){ // String taskdate = Apexpages.CurrentPage().GetParameters().get('tdate'); // Date d = date.valueof(taskdate); String goal = Apexpages.currentPage().getParameters().get('goal'); String goal2 = Apexpages.currentPage().getParameters().get('Goal2'); String goal3 = Apexpages.currentPage().getParameters().get('Goal3'); String strat = Apexpages.currentPage().getParameters().get('strat'); List a = new List(); a = [Select account__c from Account_plan__c where id = :CurrentAcct]; Ntask = new Task(); Ntask.ActivityDate = date.parse('5/25/13'); Ntask.Subject = strat; Ntask.OwnerId = CurrentUser; Ntask.WhatId = a[0].account__c; Ntask.Status = 'In Progress'; Ntask.Priority = 'Normal'; Ntask.Type = 'Call'; Ntask.Goal_Name__c = goal; try{ insert Ntask;} catch (Exception e) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'There was an Error! Cannot Create Task')); Ntask.addError(e.getMessage()); } finally { System.debug('Insert Task Error'); } SearchTact(); return null; } This code works without passing parameters, if I were to preset the variables in my controller. I have already tested it. I tried passing them with Javascript and it's not working at all. Any help would be great.

Solutions/Answers:

Answer 1:

You’re pretty close, but unless you want to go all javascript for a reason (there are plenty), using the native getters and setters with a command button is a lot easier.

VisualForce Snippet

<apex:inputText value="{!goal}"/>
<apex:inputText value="{!goal2}"/>
<apex:inputText value="{!goal3}"/>
<apex:inputText value="{!strat}"/>
<apex:commandButton value="New Task" action="{!newTask}"/>

Controller Snippet

public String goal { get; set; }
public String goal2 { get; set; }
public String goal3 { get; set; }
public String strat { get; set; }

public void newTask() {
  // access params directly via controller properties
  Task t = new Task(
      goal__c = goal
    , goal2__c = goal2
    , goal3__c = goal3
    , strat__c = strat
  );
  insert t;
}

Answer 2:

Instead of using:

  String goal = Apexpages.currentPage().getParameters().get('goal');
String goal2 = Apexpages.currentPage().getParameters().get('Goal2');
String goal3 = Apexpages.currentPage().getParameters().get('Goal3');
String strat = Apexpages.currentPage().getParameters().get('strat');

Follow the pattern here, assigning the variables to the controller via getters/setters

For example:

string goal;

public setGoal(string n){
   this.goal = n;
}

public getGoal(){
   return this.goal;
}

public AddTask(){
   // perform actions for method, goal will be assigned when actionfunction is run 
}

References