Trim leading zeros
This javascript will remove leading zeros from a question and return the value with the zeros removed.
Resolution
To use this javascript place the javascript below and call the trimZeros function with the appropriate paramter.
Examples Usage:
//show an alert message with zeros removed from the question //value of question 'Number with Leading Zeros' alert(trimZeros('Number with Leading Zeros'))' //set the question 'Number without Leading Zeros' with with zeros removed //from the value of question 'Number with Leading Zeros' KD.utils.Action.setQuestionValue('Number without Leading Zeros', trimZeros('Number with Leading Zeros'));
Javascript:
/** * Trims leading leading zeros * @method trimZeros * @param qstn {String} The question label of the question to trim zeros. * @return qstn with leading zeros removed */ function trimZeros(qstn) { qstn = KD.utils.Action.getQuestionValue(qstn); while (qstn.substr(0,1) == '0' && qstn.length>1) { qstn = qstn.substr(1,9999); } return qstn; }