I have three text prompts and want to validate them as a group, requiring the user to input value in one or more prompts before proceeding.
For e.g. I have First Name, Last Name and Student ID fields and want to group these together such that the user has to input value in at-least one prompt before proceeding. Here is what I have so far, but it is not recognizing the value in second and third fields.
var report = cognos.Report.getReport('_THIS_');
var fName = oCR.prompt.getControlByName('FirstName');
var lName = oCR.prompt.getControlByName('LastName');
var studentId = oCR.prompt.getControlByName('StudentID');
var prompts = [fName ,lName ,studentId];
var i = 0;
var promptsLength = prompts.length;
for ( i = 0; i < promptsLength ; i++) {
prompts[i].setValidator(validate);
}
function validate() {
var result = false;
for ( i = 0; i < promptsLength; i++) {
if (prompts[i].getValues().length > 0) {
result = true;
}
if (prompts[i] != this) {
prompts[i].checkData();
}
}
return result;
}
Related
Can someone one help me make this work:
I have a Checkbox for a non-repeated array. If checkbox is checked to remove duplicates it works fine, but if I uncheck remove duplicates, the checkbox still removes duplicates.
I want to make it work in such a way that if (remove duplicates) checkbox is not checked, extract all emails without removing duplicates.
Thanks.
You were just a couple lines off... when you go to output the emails you need to check for the field that determines if you should use all the emails or the unique (not repeated) emails:
<script type="text/javascript">
function findEmail() {
var email = "No email address detected";
var a = 0;
var ingroup = 0;
var separator = document.extractor.sep.value;
var groupby = Math.round(document.extractor.groupby.value);
var outputEmails = [];
if (separator == "new") separator = "\n";
if (separator == "other") separator = document.extractor.othersep.value;
//match the email pattern in large text pasted in textarea.
var rawemail = document.extractor.rawdata.value.match(/([a-zA-Z0-9._-]+#[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
var norepeat = new Array();
if (rawemail) {
for (var i=0; i<rawemail.length; i++) {
var repeat = 0;
// Check for repeated emails routine
for (var j=i+1; j<rawemail.length; j++) {
if (rawemail[i] == rawemail[j]) {
repeat++;
}
}
// Create new array for non-repeated emails
if (repeat == 0) {
norepeat[a] = rawemail[i];
a++;
}
}
// For output, use all or unique (non-repeated) emails?
outputEmails = document.extractor["non-repeated"].checked ? norepeat : rawemail;
if( document.extractor["sortbox"].checked ) {
outputEmails = outputEmails.sort();
}
email = "";
// Join emails together with separator
for (var k = 0; k < outputEmails.length; k++) {
if (ingroup != 0) email += separator;
email += outputEmails[k];
ingroup++;
// Group emails if a number is specified in form. Each group will be separate by new line.
if (groupby) {
if (ingroup == groupby) {
email += '\n\n';
ingroup = 0;
}
}
}
}
// Return array length
var count = norepeat.length;
// Print results
document.extractor.count.value = count;
document.extractor.rawdata.value = email;
}
</script>
JSFiddle example: https://jsfiddle.net/jimbo2150/ucvLtsts/21/
I am creating a Judging Form for a research competition and I am trying to use Google Forms to do so. What I am attempting to do is have a drop down list the Research Poster Numbers and have then have the user selected choice from the drop down fill text field for the poster title. I will be pulling the both the Poster Number and Title from an existing spreadsheet.
var caseScoreForm = FormApp.openById('FormTitle');
var scoreSheet = SpreadsheetApp.openById('SpreadSheetName');
var lastRow = scoreSheet.getLastRow();
function fillposterNumbersDropDown(posterNumberRange) {
var posterNumber = caseScoreForm.addListItem();
var posterNumberValue = "";
var posterNumberLog = "";
var posterNumberArr = [];
var posterNumberRange = scoreSheet.getRange('Score Sheet!A2:' + lastRow).getValues();
// loads the posterNumber array
for (var i = 0; i < posterNumberRange.length; i++) {
posterNumberValue = posterNumberRange[i][0];
Logger.log(posterNumberValue);
posterNumberLog = posterNumber.createChoice(posterNumberValue);
posterNumberArr.push(posterNumberLog);
}
posterNumber.setTitle('Poster Number:').setChoices(posterNumberArr).setRequired(true);
}
function setPosterTitleTextResponce(posterTitleRange) {
var posterTitleRange = scoreSheet.getRange('Score Sheet!B2:' + lastRow).getValues();
var posterTitle = caseScoreForm.addTextItem();
var posterTitleValue = "";
var posterTitleLog = "";
var posterTitleArr = [];
var posterNumberIndex = null;
var posterNumberChoices = FormApp.getActiveForm().getItems(FormApp.ItemType.LIST)[1].asListItem().getChoices();
var userChoice = getUserChoice();
//get the users choice index from the posterNumber dropdown
if (userChoice != null) {
for (var i = 0; i < posterNumberChoices.length; i++) {
if (userChoice == posterNumberChoices[i]) { // need getUserChoice();
posterNumberIndex = i;
break;
}
}
}
//loads the posterTitle array
for (var i = 0; i < posterTitleRange.length; i++) {
posterTitleValue = posterTitleRange[i][0];
posterTitleLog = Logger.log(posterTitleValue);
posterTitleArr.push(posterTitleLog);
}
//print out the posterTitle using the posteNumbers index
posterTitle.setTitle('Poster Title:').setRequired(true); // need way to wright to textfield
}
I think all I have left to do is just get the users choice for the active form and print it to the poster Title text field. I know there is the Get pre-filled URL link in Google forms, but we are projecting about 200 entrees for this competition.
If any one has any help/tip/suggestions or have any alternatives, please let me know.
Is there a way to use the qualtrics javascript api (or, if not, a workaround) to programatically clear all entries made to radio buttons on a page?
My usage case is in a matrix table question that "pipes" (actually uses embedded data) values from the previous question to puts calculated numbers into the statements. However, if the respondent navigates back then when the return to the following question the numbers have changed but the responses have remained. As such, if it is the second time a respondent is viewing a page constructed like this, I want to clear all their previous answers.
I want to make sure that qualtrics' data is updated properly.
My survey is currently using the JFE engine if that makes a difference.
Qualtrics.SurveyEngine.addOnload(function() {
var QID = this.questionId;
var that = this;
var counts = [];
var radioButtonsClean = [];
var radioButtons = $(QID).getElementsByTagName('input');
var radioIndex = [];
for(var i=0; i<radioButtons.length; i++) {
if(radioButtons[i].type == 'radio') {
radioButtonsClean.push(radioButtons[i]);
radioIndex.push(radioButtons[i].id);
}
}
// Set counts for each displayed radio button to 0
for(var i=0; i<radioButtonsClean.length; i++) {
counts[i] = 0;
}
this.questionclick = function(event,element){
if (element.type == 'radio') {
var thisId = element.id;
var spotCheck = radioIndex.indexOf(thisId);
var count = counts[spotCheck];
if (count == 0) {
for(var i=0; i<counts.length; i++) {
counts[i] = 0;
}
counts[spotCheck] = 1;
}
else {
this.setChoiceValue(element.id.split('~')[2], element.id.split('~')[3], false);
counts[spotCheck] = 0;
}
}
}
});
How to Verify my text boxes? This is a JSP page created to take in information.
First name should no have Numbers in there, I can enter the name as "103249" and the text box takes it. Also, How do I fix the last name as well?
var btn = "";
function validate(myform) {
if (btn == "submit") {
//Validate Form only on 'submit' button (not for 'clear' button)
var num = 0;
var message = "";
if(myform.firstname.value == "") {
message += "- First Name must be completed \n";
num = 1;
}
if(myform.lastname.value == "") {
message += "- Last Name must be completed \n";
num = 1;
}
if(myform.dateofbirth.value == "") {
message += "- Date of Birth must be completed \n";
num = 1;
}
//RADIO BUTTON VALIDATION
var g = "";
//Loop thru each radio button, verify if "checked"
for (var i=0; i<myform.gender.length; i++) {
if (myform.gender[i].checked) {
//Changes value of "g" if a value is selected
g = myform.gender[i].value;
}
}
//If no radio button selected, "g" will still = ""
if (g == "") {
message += "- Gender must be completed \n";
num = 1;
}
if(myform.gpa.value == "") {
message += "- GPA must be completed \n";
num = 1;
}
//Dropdown
if(myform.education.value == "") {
message += "- Education must be completed \n";
num = 1;
}
//Dropdown
if(myform.job.value == "") {
message += "- Occupation must be completed \n";
num = 1;
}
//RADIO BUTTON VALIDATION
var g = "";
//Loop thru each radio button, verify if "checked"
for (var i=0; i<myform.married.length; i++) {
if (myform.married[i].checked) {
//Changes value of "g" if a value is selected
g = myform.married[i].value;
}
}
//If no radio button selected, "g" will still = ""
if (g == "") {
message += "- Married must be completed \n";
num = 1;
}
//if(myform.spouse.value == "") {
//message += "- Spouse must be completed \n";
//num = 1;
//}
//RADIO BUTTON VALIDATION
var g = "";
//Loop thru each radio button, verify if "checked"
for (var i=0; i<myform.children.length; i++) {
if (myform.children[i].checked) {
//Changes value of "g" if a value is selected
g = myform.children[i].value;
}
}
//If no radio button selected, "g" will still = ""
if (g == "") {
message += "- Children must be completed \n";
num = 1;
}
//Dropdown
//Only require if previous field Children marked "Yes"
if(myform.numchild.value == "0" && g == "Yes") {
message += "- Number of Children must be completed \n";
num = 1;
}
if(myform.childSupport.value == "") {
message += "- Child Support must be completed \n";
num = 1;
}
if(myform.creditScore.value == "") {
message += "- Credit Score must be completed \n";
num = 1;
}
if (num == 1) {
alert ("Please complete or correct the following required fields: \n\n"+message);
return false;
} else {
return true;
} //end if
} //end if submit button
if (btn == "delete") {
//Confirm if want to delete
var result = confirm("Are you sure you want to permanently delete this survey?");
return result;
} //end if delete button
} //end func
//=============== TO DISABLE CCARDS AND NUMBER OF CHILDREN DROPBOXES ==================
function handleSelect(myRadio){
if(myRadio.value == "No"){
document.getElementById("cc_use").selectedIndex = 0; //reset to initial default value
document.getElementById("cc_use").disabled = true;
} else {
document.getElementById("cc_use").disabled = false;
} //end if
} //end func
function handleSelect1(myRadio1){
if(myRadio1.value == "No"){
document.getElementById("numchild").selectedIndex = 0; //reset to initial default value
document.getElementById("numchild").disabled = true;
} else {
document.getElementById("numchild").disabled = false;
} //end if
} //end func
//=============== POPULATE OCCUPATION DROPDOWN BASED ON INDUSTRY DROPDOWN SELECTION ==================
function configureDropDownList(industry, occupation) { //params: id's of sending dropdown & dropdown to change
//Categories: Create a String value of all the list items in the Java ArrayList of Categories
//It translates into a String with opening and closing brackets: [], need to delete brackets from String
var categoryListString = "<%= lstCategories %>";
categoryListString = categoryListString.replace("[","");
categoryListString = categoryListString.replace("]","");
//Split the Category String into a new Javascript array of Categories
var categoryArray = new Array();
categoryArray = categoryListString.split(", "); //Make sure it's comma + space
//Occupations: Create a String value of all the nested list items in the Java ArrayList of ArrayLists: all occup names for each category
//It translates into a String with opening and closing DOUBLE brackets: [[]], need to delete brackets from String
var occupByCatsString = "<%= loccp %>";
occupByCatsString = occupByCatsString.replace("[[","");
occupByCatsString = occupByCatsString.replace("]]","");
//Split the String into a new Javascript array
var occupationsArray = new Array();
occupationsArray = occupByCatsString.split("], [");
//Loop thru array and break into further individual nested arrays for occup names in each category
for (var i = 0; i < occupationsArray.length; i++) {
occupationsArray[i] = occupationsArray[i].split(", "); //Make sure it's comma + space
}
//alert("new occup name array index 0: "+occupationsArray[0]+", index 1: "+occupationsArray[1]);
//alert("Individ occup names in index 0, name 0: "+occupationsArray[0][0]+", name 1: "+occupationsArray[0][1]);
//Categories array (categoryArray) & Nested Occup Names Array by Category (occupationsArray)
//are parallel arrays in order to match Category names with appropriate group of Occup Names
//Loop thru list of all Categories to find selected one
//and create dropdown list of matching Occup Names for that Category
for (var i = 0; i < categoryArray.length; i++)
{
if (industry.value == categoryArray[i]) {
//Call method to create Occupation dropdown list values
//Send array of that Category's list of Occupation Names as parameter, and 'occupation' id value of select
createOccupationItems(occupationsArray[i], occupation);
}
} //end for
} //end function
function createOccupationItems(occupArr, occupation) {
//Parameters in: array of that Category's list of Occupation Names, and 'occupation' id value of select
document.getElementById(occupation).options.length = 0;
for (var i = 0; i < occupArr.length; i++) {
createOption(document.getElementById(occupation), occupArr[i], occupArr[i]);
}
} //end function
function createOption(ddl, text, value) {
var opt = document.createElement('option');
opt.value = value;
opt.text = text;
ddl.options.add(opt);
} //end function
</script>
Here is the actual code to validate:
<div class="sameLine">
<label for="firstname">First Name:</label>
<input type="text" name="firstname" value="<%=surv.getFname()%>">
</div>
<div class="sameLine">
<label for="lastname">Last Name:</label>
<input type="text" name="lastname" value="<%=surv.getLname()%>">
EDIT: Here is the code that I found to verify the letters. It does not work, ignoring it if anything:
if(myform.firstname.value.search(/[^a-zA-Z]+/) === -1) {
message += "- First Name must have letters only \n";
num = 1;
}
I have this code that sends the values a user have typed in... the information and numbers are sent as an array and pushed into another array, I then display the text in a dynamically created list element and number in a span element...
var button = $('#add');
button.click(function()
{
var filmnamn = $('#name');
var filmnamnet = filmnamn.val();
var betyg = $('#star');
var betyget = betyg.val();
betyget = Number(betyget);
if(filmnamnet == 0)
{
$('#name').css('background-color', 'red');
}
if(betyget == 0)
{
$('#star').css('background-color', 'red');
}
if(betyget == 0 || filmnamnet == 0)
{
alert("Vänligen fyll i fälten korrekt");
}
else
{
var array = new Array();
array.unshift(betyget);
array.unshift(filmnamnet);
film_array.unshift(array);
betyg_array.unshift(array);
updateFilmList();
}
});
var film_list = $("#filmlista");
var film_array = new Array();
function updateFilmList()
{
document.getElementById("name").value = '';
document.getElementById("star").value = 0;
var filmen = film_array[0][0];
var grade = film_array[0][1];
var element = '<li class="lista">' + filmen + '<span class="betyg">'+ grade +'</span></li>';
film_list.append(element);
changeNumber();
}
And at last I have the function that i want to change the number in the span element to the amount of stars that the number shows... this works fine but only for the first created list and span element, when I try to add more listelements the number wont show up as stars, can someone tell me why this happens and point me in the direction to fix the problem?
function changeNumber(){
var elements= document.getElementsByClassName("betyg");
for (var i=0; i<elements.length; i++) {
var element = elements[i];
var length = parseInt(element.innerHTML);
var x=Array(length+1).join("*");
element.innerHTML=x;
}
}