I have 10 small text field boxes in HTML where I want users to enter numbers 1 to 10 - and the same number can not be entered twice in another box.
I'm struggling to work out how to accomplish this in Javascript/jQuery.
Any help would be appreciated.
Simply create an array with the values and check for duplication.
var formdata=new Array();
formdata[0]=document.getElementByid('id').value;
formdata[1]=document.getElementByid('id').value;
formdata[2]=document.getElementByid('id').value;
Now check for duplications in the array using the following - I guess the following question would be useful on stack overflow:
Easiest way to find duplicate values in a JavaScript array.
If the breakpoint is one simply display an alert() to the user to renter the data.
Instead of using documents.getElementById() you can also use
oForm = document.forms[index];
oText = oForm.elements["text_element_name"].value; OR
oText = oForm.elements[index].value;
More information can be found at:
http://www.javascript-coder.com/javascript-form/javascript-get-form.phtml
Related
I am trying to input the content of a variable generated with the Automator app onto the next action step, to define the value of a javascript script variable. Change the variable using javascript code and push the result further to the next action step. Then turn it back into an Automator variable, or update the one previously used as input. I am sure you will find it as a simple thing, but I couldn't find a way to get it working. This question might be silly, after all. Many thanks in advance. Check the screenshot of the Automator sequence of steps. Screenshot of the actions set in Automator App
function run(input) {
var str = input;
var l1 = str.replace(/ /g, "_");
str = l1;
var l2 = str.replace(/:/g, "-");
return l2;
}
The input to an Automator action is an array, so you will need to step through the array or convert/coerce to whatever class you are wanting to work with. In your posted script, the replace() method is for a string, so you are getting an error trying to use that method on the input array.
If you just want a single input item you can use input[0] to get the first item in the array, or input.join() to join the array items together.
Very new to Javascript and have been searching the webs for assistance, but haven't quite found a solution.
I am attempting to use javascript to split/remove the output of a particular field. The data in the survey is being pulled from our school's database after a user logs in to the survey via shibboleth. All the information is being displayed, so that part works, but one particular field is appending an email address (#email.com) to a field.
I want to omit this part from being displayed. Either my javascript is incorrect or the javascript is not being loaded/read. The javascript code was borrowed from a colleague and it works on his surveys, but he has a lot of other things going on in his survey and this works for him.
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var iid = "${e://Field/theUTIID}";
var split_array = iid.split("#",1);
var eid = split_array[0];
Qualtrics.SurveyEngine.setEmbeddedData('theUTIID', eid);
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var iid = "${e://Field/theUTIID}";
var split_array = iid.split("#",1);
var eid = split_array[0];
Qualtrics.SurveyEngine.setEmbeddedData('theUTIID', eid);
});
I have this in both the Onload and OnReady for testing. Doesn't matter if I have this is one location or the other, I am not getting the desired results.
I only have one question on the survey (it's just a test survey) and so the javascript code is with the first and only question.
Survey Question has the following in a text entry. Again, output is displayed, but need the #email.com to removed from the EID field.
The code looks correct (other than it only needs to be in one or the other function). I'm guessing it isn't a problem with the code, but where you are trying to pipe the embedded variable. The JavaScript above has to be attached to a question on a separate page before the place where you want to pipe it.
Add a page break, then pipe theUTIID into a question on the next page.
I'm currently looking to run a simple script using jQuery and TamperMonkey as I'm doing a recurent job which is time consuming and that should be pretty basic, not sure how to achieve the below (I've recorderd a gift) - I'm new to jQuery/coding, but searching arround, using this:
//Get
var IPG = $('#txt_name').val();
//Set
$('#txt_name').val(IPG);
might be where to look at?
the script should scan the field IPG ID where -1 are present, copy the name from the channel description and copy it to IPG description
https://gyazo.com/f4bd243827df598edfdd78ec1a2d53b5
any help in achieving this would be appreciate,
many thanks,
I named HTML elements' ids by myself because I simply don't know what are those fields' id named in your app.
What you are trying to achieve it is really simple and this code can do you the trick:
var IPG = $('#IPGid').val();
if (IPG==-1)
{
var toCopy = $('#ChannelDescription').val();
$('#IPGDesc').val(toCopy);
}
Note:
This can only be done once the page is loaded it is not live for every action.
This cannot treat all lines of the table you should figure your way out of how turning it dynamic to the whole table.
I'm having trouble iterating over all of the fields in my document to remove the tooltip. Here's my code:
var index=0;
while(index<this.numFields)
{
var nom=this.getNthFieldName(index);
var fieldName=this.getField(nom);
fieldName.userName = "";
index=index+1;
}
I'm getting an error saying fieldName is null and my script won't run. I've seen this answer already:
Iterating over all fields in a PDF form with JavaScript
I get the same error with that code too. If I manually assign a field name to fieldName using var fieldName=this.getField("field1");, it works fine.
Does anyone have any idea why this would error on me?
Edit:
I can iterate over the list and output nom to the console so I know it's grabbing the names of the fields properly. It seems to have trouble dropping that name into the this.getField(nom) statement. No idea why...
Why use while… for this?
Doing exactly the same (setting the mousetip text to a blank string) is simpler using
for (var i = 0 ; i < this.numFields ; i++) {
this.getField(this.getNthFieldName(i)).userName = "" ;
}
and that should do it.
However, unless you have a very good reason, setting the userName to the blank string is not recommended; it is needed if your form is used with assistive devices, and it is also the very nearest and simplest help item.
I figured out my issue.
When I created the form, I used the automatic field detection to create my fields for me in order to save time (there are like 250 fields on this form). The reason I needed the script in the first place was to remove the crummy tooltip names that the feature generates.
Apparently, in its infinite wisdom, the field detection feature named a handful of fields with a leading space ( something like " OF INFORMATIONrow1"). Since getNthFieldName(index) returns the fields in alphabetical order, it was returning one of these broken fields and erroring immediately because getField() doesn't like the leading space in the name.
I renamed the handful of fields and the script works like a charm.
I am working on an AngularJS app that has a Slickgrid on it. I am trying to write a test and im running into a problem. When I use Selenium I can get it to click in one of the cells but the sendkeys function doesn't seem to do anything, no text is entered even though I can see the cursor flashing in the cell.
Even if I record my actions in Selenium IDE, no actions are recorded for entering text in the cell.
I've tried opening the JavaScript console in chrome and writing some JavaScript to enter some text in one of the cells and made zero progress (I don't know JavaScript).
What JavaScript can I use in the chrome console to enter text in one of the cells? Does selenium not work well with SlickGrid?
I'm not sure what the best approach is here.
Thanks
It seems that you are asking about two things at once. I will try to emphasize that I have no experience in Selenium, but I can try answering the JavaScript part.
You didn't share too much information about your actual SlickGrid setup, so my solutions for your question are based on the official SlickGrid: Making it editable example, which you could try these methods on, for instance using the JavaScript ScratchPad.
I will share the two methods I have found, since I don't know which one could you integrate to your Selenium setup.
Method 1 - via the SlickGrid API:
var row = 0;
var cell = 0;
var test_input = 'Your input';
if(grid.canCellBeActive(row, cell)) {
grid.setActiveCell(row, cell);
grid.editActiveCell();
var activeCell = $(grid.getActiveCellNode());
if(typeof activeCell !== 'undefined') {
activeCell.children(0).val(test_input);
grid.gotoCell(row, cell);
}
}
Method 2 - via setting the data source of your grid.
In this case it's a JavaScript array of objects:
var row = 0;
var test_input = 'Your input';
data[row].title = test_input;
grid.invalidateRow(row);
grid.render();
These two methods both change the given cell data, the main difference is that using the second method you need to rely on the field name property you want to set.