Store date picker date and save in database - javascript

Im trying to get the date from a date picker i have on my page and then have that date posted to a php function which will store the selected date in my database.

I think you have a misunderstanding of how Javascript, HTML forms, and PHP work together.
Javascript (and jQuery) run in the browser. PHP runs on your server.
The browser initiates a request to your server, your server hands off the request to a php process which parses and runs your php. This generates html which is sent back to your browser. The javascript linked to or contained in <script> tags is then loaded, and run if necessary (or triggered by events). This is an oversimplification, but should get across the basics.
So, what is happening is the jQuery is running inside your browser to perform changes to the HTML. Specifically, it is inserting a string formatted as 'MM-DD-YYY' into your form field. When the user then posts this form, those values get added to the HTTP request that is sent to your server. Those values are then accessible in the $_POST variable in your php script, as a key=>value pair, where key is the HTML name='formfield1' attribute of your form. So your would access that as $date = $_POST['formfield1'].
Javascript, and jQuery specifically are doing nothing but loading a string value into that html field for the user. You can't access Javascript variables from your PHP.
If you post your form code, a more specific answer might be able to be given.
Edit: for an inline datepicker, you will need to configure your datepicker as follows:
$('#datepicker').datepicker({
inline : true,
altField : '#hiddenFieldID',
});
where #hiddenFieldID is a hidden input field in your form. Regardless, you have to attach the date value to your form in some way for it to be available in $_POST.

Related

How to extract data from form input data-bind generated in realtime

I am trying to automate a task of authentication via Azure ActiveDirectory. I was writing my script as per the browser requests. On seeing the request, I notice that browser is sending a parameter in url-encoded form.
The parameter is being sent as i19.
<input type=hidden name=i19 data-bind=\"value: timeOnPage\"/>'
On going through internal scripts of the page I find the above input type where i19 is being assigned a value dynamically.
I need to generate this value to form a encoded string parameter to be sent to next location url for authentication.
It does not look like an EPOCH UNIX timestamp either.
For Eg: At roughly about 13:53:58 IST, i19: 55964
Now I am unable to find what exactly is going in this i19.
I am attaching a response script here for the script where this input is being generated.(It is a long file so attached separately). All I know that some value is being created dynamically and browser understands it but via python post request, javascript is disabled and the value is not being shown in response/headers/cookies.
I shall be really grateful for the same.

Return data from SQL based on user input without reloading form - Classic ASP

I am working on adding a new feature to an existing Classic ASP application. In this feature the user will scan a bar-code which will input its value into a text field in a form within a bootstrap modal. The scanner is configured to send a TAB as well after the data.
What I need is a way to query the database on field exit and populate other fields in the modal with data from the query that is based on the scanned value. I need to do this without reloading the page or closing the modal so the user can verify this information and make changes before saving the form.
What is the best way to do this? I have no issue writing the SP, but do not have any idea how to call it and then return it's values. Can I possibly use JavaScript/PHP for this?
You will need to use some ajax
https://learn.jquery.com/ajax/
Basically you would send a request to your .asp script which will run the stored procedure then send a response using Response.Write.
Then parse that response in jquery.
Unlike ASP Classic, AJAX is a new technology so it works better with JSON.
There aren't many JSON libraries
You can use json2.asp:
https://github.com/nagaozen/asp-xtreme-evolution/blob/master/lib/axe/classes/Parsers/json2.asp
Or if you want you can try it XML, but its unpopular these days and more tedious to parse.
You mentionned PHP, that's not a bad idea because, it's all built in for you see:
http://php.net/manual/en/function.json-encode.php
Hope this helps

Parse a Json response array from server in javascript without loading the page

I am working on a webapp. I have a webpage that sends some data to the server via form tag. The server returns a json array. I want to know how to parse that json array without loading
my page. The purpose is to keep my webpage as it is and load some values from json array to
some text fields below my form tag for further processing.
edit: I have tried some examples for reading from json array but how to prevent webpage realoading.
Please use Ajax for this. Ajax calls are done using Javascript as per your requirement. If you are using library like JQuery it is quite simple to use.
Link to JQuery - Get: http://api.jquery.com/jQuery.get/
One of the ideas to save you from changing anything in your existing code is handle onsubmit of the form. Send your get/post on submit via ajax and cancel the submit of the form.

load file and write in xml or html?

I am curious if this is possible:
on the website:
using jquery to get value from a html tag and store the value as a variable
using ajax to call a file (xml, html or txt) on servside or external site for a php file
define the current value in the xml html or txt file
and add this value to the current value. = new value
store this new value in the xml html or txt (saving the file on server...)
Q1. Is this achievable?
Q2. If so, what file is best used/supported? (php would be my very last alternative option) I prefer xml and html...
Q3. step 1 to 4 i can get to work - but step 5 i have totally no experience in. Anyone can guide me the right direction for writing those documents?
You cannot write the file directly in the server using javascript.
What you can do, for example, is send the updated data to a page in the server (sending a request to a PHP page, or a MVC endpoint, or whatever server-side technology you want to use) and then have the server code update the file using that data.
You can do this with AJAX (eg. using jQuery with $.post) if you want it to happen in the background, or with a normal request (which will reload the page or take the user elsewhere depending on the server code).

Flow of Jsp -> Javascript webpage (Ajax?)

I am making a website but I get a bit lost programming dynamic sites.
The user needs to enter x (inside a textbox), click submit, process in java (serverside) and present outcome as a report to the user (using javascript).
I'm at the moment using JSP to process the users input but now I need to pass the JSON code into the javascript. The javascript requires JSON data.
At the moment I have JSP which returns the necessary JSON code and the Javascript which works with hardcoded JSON code. I need to somehow store the returned JSON (from the JSP) in a variable and pass it to the Javascript. I have a vague understanding of AJAX - i'm just unsure if this is possible and how to link it all together.
Thank you.
Your JSP "page" can simply generate JSON directly. There's no reason the output from JSP has to be HTML. From the client, therefore, you POST to the server, the JSP runs, and the result (pure JSON from your JSP) is sent back to the client as the ajax response.
Sounds like the perfect place for AJAX - you can submit the request with javascript, and when it comes back process it further with javascript. Unless you want the page to refresh.
If you are using jQuery, you can look here to see how to implement it, should be relatively painless: http://api.jquery.com/jQuery.post/

Categories

Resources