You are viewing limited content. For full access, please sign in.

Question

Question

dynamically created drop down not saving

asked on March 20, 2018 Show version history

I have a drop down that populates its values starting from the current month using Javascript:

var date = new Date();
var currentMonth = date.getMonth();
var futureMonths = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var i = 0;
var optionString = "";    
var mStartIndex = currentMonth;
var mEndIndex=12;

for (i = mStartIndex;i <mEndIndex; i++)
{
   optionString = optionString + "<option value=\""+  i + "\">" + futureMonths[i] + "</option>\n";       
}
    
  $("#Field21").html(optionString);

The choice that the user selects from this drop down don't get saved when the form is saved to the repository.  

Any help would be appreciated.

 

Thanks!

0 0

Answer

SELECTED ANSWER
replied on March 21, 2018

Did you still keep the above script on the form saved to repository? If so, the script would overwrite the html content of the field so it won't show the selected value.

I used the following script and value could show correctly on file saved to repository:

$(document).ready(function(){
  if ($("input[name='IsLocked']").val() == "False")
  {
    var date = new Date();
    var currentMonth = date.getMonth();
    var futureMonths = ['January','February','March','April','May','June','July','August','September','October','November','December'];
    var i = 0;
    var optionString = "";    
    var mStartIndex = currentMonth;
    var mEndIndex=12;

    for (i = mStartIndex;i <mEndIndex; i++)
    {
       optionString = optionString + "<option value=\""+  futureMonths[i] + "\">" + futureMonths[i] + "</option>\n";       
    }

    $("#Field21").html(optionString);
  }
});

 

0 0

Replies

replied on March 20, 2018

Hi Purvi,

The drop-down field options you added have inconsistent choices and values, and the actual submitted value is the value, not the choice.

I tried your script and it would submit value "4" when I chose choice "May".

0 0
replied on March 21, 2018

If I change 

optionString = optionString + "<option value=\""+  i + "\">" + futureMonths[i] + "</option>\n";

to 

optionString = optionString + "<option value=\""+  futureMonths[i ]+ "\">" + futureMonths[i] + "</option>\n";

it still doesn't store the values in the repository.

0 0
SELECTED ANSWER
replied on March 21, 2018

Did you still keep the above script on the form saved to repository? If so, the script would overwrite the html content of the field so it won't show the selected value.

I used the following script and value could show correctly on file saved to repository:

$(document).ready(function(){
  if ($("input[name='IsLocked']").val() == "False")
  {
    var date = new Date();
    var currentMonth = date.getMonth();
    var futureMonths = ['January','February','March','April','May','June','July','August','September','October','November','December'];
    var i = 0;
    var optionString = "";    
    var mStartIndex = currentMonth;
    var mEndIndex=12;

    for (i = mStartIndex;i <mEndIndex; i++)
    {
       optionString = optionString + "<option value=\""+  futureMonths[i] + "\">" + futureMonths[i] + "</option>\n";       
    }

    $("#Field21").html(optionString);
  }
});

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.