Log text value into a textarea in a for loop - javascript

Okay, so, just to clear this idea up, I couldn't crack a custom encryption code, and so I just tried to find a way to log all of the encryptions for the codes I want into a textarea and copy them. If that doesn't make sense, just tell me, I'll try to explain it in a more detailed way.
The encryption would work by taking what you typed in a textbox, encrypting it, and then submitting the form with the encryption. I'm attempting to take advantage of this by removing the submission, and using a for loop to enter a number into the textbox, calling the encryption function, then logging the encryption into a textarea. Heres the code:
function encryption(form) {
for (var i = 100; i < 1000; i = i + 1) {
document.getElementById("fieldPassword").innerHTML =
i
doPCASLogin(form)
var passwordinpforlist = document.getElementById("fieldPassword").innerHTML;
document.getElementById("outputlistfordecryptions").innerHTML =
passwordinpforlist
}
}
I'm not entirely sure what's wrong. Nothing will even log to the textarea. But, the encryption will still appear in the password text box like it's supposed to. The ID for the textbox is "fieldPassword". Yes, I checked that the ID for the textarea was "outputlistfordecryptions". And if you're wondering about doPCASLogin, it's the encrypting script. And it automatically changes the password field to the encryption.
If I'm missing something, please tell me. By the way, everything seems to work except for logging to the textarea. Maybe I incorrectly made the variable or something?

Related

Adobe Acrobat - Error Iterating Over All Fields in a PDF with JavaScript

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.

Why cant I get the text boxes to POST/GET when I submit

Here is the dom:
This is how I am submitting:
function createOrderItems(){
showCustomPanel(" Creating Order Items ");
$("#order_items")[0].submit();
return false;
}
Here you can see that the text field isnt getting picked up:
You need name attribute on it to get it included in params
To add more detail to the answer already given, If you don't give the input a name then it has nothing to assign the information to that is entered into the text box.
Think of it like a variable
= "stuff"; wont do anything
this = "stuff"; will store stuff into this. Then you can use that information later.
Not really how it works on the back end but it is a good way of understanding it.

Meaning of JavaScript form validation code?

I have to explain how a specific Javascript code validates a web form, but I am stuck with what some of the features do, most specifically this section of the code. I understand that the first line defines that the rest of the section should only run if the field Field1 of the form ExampleForm is left empty, but I do not know what purpose the rest of the code serves. All I know is that msg is a variable created earlier in the document with an empty default value, and that result is another variable with a default value of true. Can anyone help me out by explaining what each line does?
if (document.ExampleForm.Field1.value=="") {
msg+="You must enter your name \n";
document.ExampleForm.name.focus();
document.getElementById('Field1').style.color="red";
result = false;
}
In plain english:
If the document form field value is equal to an empty string, set the error message to msg, then focus on the element, and give is a red color so the user knows it's an error, and set the result to false, for whatever you're going to use that for later in your code/function.
So this would in part depend on what other code is on the page. For example document.ExampleForm is not part of the DOM and seems to be something someone kludged onto your page.
Overall I would say this is pretty bad code that makes a ton of assumptions that won't necessarily hold up written by someone who doesn't understand in-browser javascript very well, but let's go with it
//if the value in this variable is falsy (false, empty, or 0)
if (document.ExampleForm.Field1.value=="") {
//Append this to the msg string. Note \n is usually used
//to indicate "new line" but wont' do anything on the web since that's not how line breaks
//work on the web
msg+=”You must enter your name \n”;
//Invoke the `focus` field on this variable. From the context I assume this is
//a DOM node so you are basically focusing it in the browser
document.ExampleForm.name.focus();
//Set the font color of '#Field1' to red
document.getElementById('Field1').style.color=”red”;
//Presumably result is something that tells you true/false did the validation succeed.
//set it to false to indicate failure.
result = false;
}
My guess about what document.ExampleForm is that it depends on some undocumented behavior of an old browser to add anything with id=ExampleForm to the document element. But really I have no idea. Maybe you have some code elsewhere that creates that variable. Either way its a horrible idea and should get someone yelled at.

Check Starting Form Values For JavaScript Validation

I have an HTML form that I already validate using Javascript. However, I am only checking to make sure it has been filled out. I also need to check to be sure that the first eight characters of the form do not contain "FFFFFFFF" or "ffffffff". It will be a 40 character input into the form field. I am just not sure how to do this with Javascript.
If someone could point me in the right direction, I would really appreciate it.
var txt = document.getElementById('id').value;
var first = txt.substring(0,8);
if(first=="FFFFFFFF"||first=="ffffffff"){
// validation error
else
//validation success
as simple as that. i can't be more specific since you haven't shared any of your code.

Passing HTML input form contents for calculation

I am trying to make a graph of a simple function y=k*x+b.
A user enters a function into the input field, for example:
1/3*x+3
and when he/she clicks the submit button, a JavaScript function is supposed to take this input value as an actual calculation sequence and assign a variable to it (I only need to get certain y values here, so the x variable has its limits):
for (x=1;x<=40;x++)
{
result = window.document.menu.inputFunction.value;
}
The above code doesn't work. No wonder why - I am just a beginner at this. However, is this really harder than it looks, or am I missing out something? I considered trying regular expressions for this at one point, but my head hurts by even thinking about using them.
Any ideas?
You could eval it:
result = eval(window.document.menu.inputFunction.value);
There are obviously some limitations to this approach:
The user must enter a valid javascript expression
The user must use x as variable name because that's what you are using in the loop
The code is vulnerable because the user can enter and execute any javascript expression he likes
For a more robust solution you might consider using a javascript mathematical expression evaluator.

Categories

Resources