Rewrite JSON data within a .js file when submitting HTML form - javascript

Forgive me if I dont describe my problem very well. I am a beginner with this.
Basically, I have a webpage which displays nine numerical values and beside these values is a form. The numerical values are stored as JSON data inside a .js file.
What I want is for when I type in a new numerical value into the form and click on submit, I want all the current values to move down one place (the last one getting deleted) and the new value I have entered to replace the first data entry.
I need this to work offline, so I cant use a regular database like MySql, and there will never be more than 9 items of data stored. Thats why I thought saving the data in the .js file would be best.
Any help would be greatly appreciated.

Related

Steps to access one of two scripts serving as a custom script for a text field residing on an Acrobat PDF form

I have an interactive fillable PDF form created in Acrobat. The form essentially relies on a combo box and a hidden text field containing two scripts (serving as a custom script) one that creates a number of multidimensional arrays nested inside one large array and a 2nd script that serves to populate a number of text fields residing on the PDF form by pulling data from any one of 14 multidimensional arrays depending on the combo box selection made by the end user. So far so good regarding displaying the data associated with the combo box selection. Needless to say, the data stored inside the multidimensional arrays will need to be appended and modified in time to come given data to be added, edited, and deleted. Hence, my present task entails knowing the steps required to access the multidimensional arrays in order to append and modify the data contained therein using JS. In general, I believe I first need the ability to access the entire script to be able to separate the script that creates the array from the second one. Once done, I figure I should then be able to append/modify the data in the array via scripts. Once done, I believe all that remains is to insert/replace the entire custom script so everything is in sync. What do you think, easier said than done? I hope not.
I haven't tried anything yet. Just want to make sure I'm not spinning my wheels whereby the task is impossible to achieve.
In regard to my initial post, I should have asked for a script to populate a drop-down combo box that resides on a PDF form using names stored inside a JS object converted to a JSON string that serves as a value in a hidden text field on the PDF form. Upon further study of the JS literal object, the required script is as follows:
dsFld =getField("dataSrc");// call the getField method to get the hidden text
field used to store oVendors data object as a JSON String
oVendors = JSON.parse(dsFld.value);// Parse the JSON string to manipulate the
stored oVendors data object
f = getField("cbNames");// call the getField method to get the CB drop-down
field for later use
aNames=new Array();..create a temp array
for(var key in oVendors){//script to populate the temp array from names stored
in oVendors data object
aNames.push(key);
}
aNames.sort();// sort the names alphabetically
f.setItems(aNames);// assign the names from the temp array to the combo box
field drop-down list
f.insertItemAt("Add or lookup and select a name"); // insert a string at the
beginning of the CB drop-down list
dsFld.value=JSON.stringify(oVendors);// convert oVendors back to a JSON string
Sorry for the ambiguity in my initial post and any inconvenience to the forum.

Presenting dynamic information from CSV file

So, i have googled and googled and googled. Maybe I need to improve my google skills.
Maybe the answer already exists somewhere on this page but I have not found it. Anyway.
So I am dealing with a csv file which shows date, transacation category, location and the amount of the transaction. In that order.
So what I need to do is to present this information dynamically in an HTML table. The user should be able to select the location from a dropdown menu and the table should be updated with the corresponding information about transactions done from that location.
I am able to present the overall information from the csv file, but when making it truly dynamical Im struggeling.
So I have the information stored in a 2d array [date, transaction category, location, transaction category].
So my real problem is, how do I make this truly dynamical. Meaning, how can I update the tag with without hardcoding anything. I want it to be independet of what csv file I am uploading.
I'm thinking that it would be good to have a function that loop through the array and split out the user selected array on an onchange event and then send the selecte array to output. But I cant quite imagined exactly how this would be done...
Thankfull for any suggestions. :)
Honestly, I would turn it into JSON first and go from there. One of my favorite parsers is csvtojson. It's pretty simple to use.

Fill pdf form created in scribus from client side javascript

I have a pdf form, into which I want to fill a password generated in javascript, so that the user can print it. The password is sensitive and may not be send to the server, so this has to happen in client side javascript. In this post it is possible using adobe acrobat.
The Idea is, that one creates a pre-filled form with a unique value, and than replaces that value using somple search and replace in javascript when generating the final pdf for displaying the user.
Since I do not own actobat, I thought I try it with scribus.
I generated a test form in scribus and gave it the prefilled value %HELLO%. But looking at the resuling pdf, I do not see that I can replace the %HELLO% value by the password with simple text replacement.
It turns out, while this post already gives the answer in the code it does not explain it.
The value of TextField has to be converted to a sequence of hex-encoded unicode characters (so each 4 digits) and it has to start with "fffe". Using this string, one can do the search and replace in the pdf document.
The code also updates the "xref" in the pdf, which one has to do when the length of the pdf changes (or some elements are positioned different in the file). Since I did not change the length of the value of the TextField, I did not have to do that.

How can i assign javascript array to Ftllist?

i have a list of values in javascript and the variable name is array with the values
['1','2','3'].here i want to assign this array values into a list in ftl file called list.
actually am trying to get checkbox value through js and assigning to a list which is the ftl file.
help me to overcome this issue.
FreeMarker runs on the server before the JavaScript runs on the client, so what you want is impossible. Or at least the way you want to do it, it is. You had to post that array back to the server (with a form or with AJAX), etc.
You have to send the list of values via ajax call and refresh a div to show new results.
since freemarker is a templating engine that runs on server to generate the html pages you will not be able to send any objects,lists, etc... to freemarker I could show you an example if you want.

modify contents of a js file

Hi I have a javascript array of Url's in content.js file. I need to display the urls in seperate input boxes on a seperate page say display.php. Edit and delete buttons are given along with each input boxes. any change made by the user should be reflected in the content.js file.
I have shown all the url's in the input boxes. now an onclick event calls a function on button press.
My question is what will be the best way to update the array in content.js file(the file contains only one array). I'm trying to use file handling but that will require the content.js to have a strict format always. Is there a better way to modify the contents of the array or delete rows from array without file handling?
In first step, you should read the contents of JS file and pass it to json_decode function. It will give you PHP array. Use this array to display text boxes to user.
In second step, you should get the strings the user was submitted (e.g. from $_POST) and construct a PHP array from them. Then use json_encode to convert PHP array to JavaScript array represented in a string. Then you can write this string to JS file. So its content will be always valid.
You could do it with a server-side language like PHP. See this tutorial on how to write files using PHP. I would convert the array into a string using json_encode and use json_decode to convert it back into an array after reading it.
If you're only saving these URLs for the user and nobody else (so only the person entering/editing the data needs to see it) then I recommend using HTML5 localStorage

Categories