Styled Javascript Popup that Conncects to Database - javascript

I want to create a javascript popup box that contains text fields. I want to be able to style this box - using CSS - and I want the textfield entries to be Inserted into a MySQL database. Is this possible?
I would be familiar with doing this through web forms and server side scripting but I need it to be a bit more client side this time to make things seem a bit faster. I am thinking I may need to learn some AJAX but any pointers would be a help.
GF

You don't need to learn that much Javascript, to be completely honest. You could simply create a small HTML form on your page, and display it as a popup. You could either have it send the data to your server-side script via the form's natural submit, or you could pass that information asynchronously.
jQueryUI has an example of something very similar: http://jqueryui.com/demos/dialog/#modal-form

You can't connect to a database with client-side javascript. Ajax will help you make seamless calls back to the server without refreshing pages, but you will need to have a server side component to return something useful back to your javascript.
As far as styling your forms with CSS, that part is doable.

Best way to do this would be to "popup" a new window which points to a file with the AJAX calls, the form, and the styling.

Related

Use an external webpage's form from my own website to get data (PHP)

I wonder if I can use an external form of a webpage in the web from my own website. I am creating an application using the WAMP tool and I need some PHP/JavaScript/whatever script to do it.
Basically I'd have the same exactly form in my website (or at least a similar one) as the one in the external webpage - the goal of this form is only to perform a search. The user would be capable of doing the search and seeing the results posted in my website aswell and all this happening in a hidden way.
I really have no idea how to do this as I searched stackoverflow and the web looking for a solution but it really seems a little bit complicated.
Here's an image to ilustrate more or less what I want:
edit: I don't want any script or code! I Just want to know what is the best way to do this. I will eventually come to a solution (I hope!). Thanks!
The concept is called Web Scraping, you can find more about it in https://en.wikipedia.org/wiki/Web_scraping
As an answer, you can write simple web scraper using PHP CURL.
CURL can submit a remote form for you and get the results of form submit, that results may need to be handled by your script to be displayed in the form you need.
This stackoverflow question and answer may clear it more for you.
How to submit form on an external website and get generated HTML?

Accessing html form fields with an external application

I created a command line tool to help expedite HTML form filling. It uses a brute force approach in that it sends TAB keys to a window and writes info from a config file. This is unstable so I want to refactor it to set form fields using javascript.
I've looked into writing a Firefox addon to do this. I was able to hard-code each field id and write to it from a config file. My issue is I need this functionality in IE.
Is there a way an external application (ie cmd line tool) can write to HTML fields using javascript? I've tried recreating the entire html page with form fields filled in Java. I then try to send this to the normal destination using an HTTP POST. I ran into authentication issues because the forms require a log in.
My other idea is looking into web service tricks. It may be unrelated, I have no idea.
Why not try something like Selenium?
It will stop your reliance on hard coding everything as you have pretty much free reign over the DOM.
Correct me if I'm wrong, though.
You can open an CwebBrowser2 in your C++/C# application and use it as an HTML browser and get all the HTML programatically. You can then parse the HTML with a XML parses and call certain Javascript hooks.
The HTTP Post idea still seems best, if you have trouble with authenticating you just need to mimic that part as well or get the session ID (if a given session is enough for you).

Best way of dynamically loading server controls from jQuery/Javascript

I have seen a few other questions of a similar vein on here, but with no definitive answers.
I am looking for the best way to go about loading asp.net server controls (or user controls) from client script (likely jQuery). I am creating a small dashboard that will feature multiple controls/controls created as the result of client script call's and the controls will need to be able to run server side functions and are not just simple information display controls.
I have done something similar recently with loading details controls which were rendered via an HttpHandler from a jQuery $.get() and the resulting HTML of the control is injected into the DIV area - however these used a custom formless page as a temp placeholder as to not interfere with the current viewstate/rendering cycle on the page so they were only able to use HTML elements such as hyperlinks, etc.
This is different and I am looking for the best way to be able to load up controls which will act as if they were registered into the page at the beginning of the page life cycle because I want the controls to be able to run their own server side methods/events (some filtering, etc).
I have seen some people say you should really use UpdatePanel's for this and do the processing server-side - but I am loathe to do this as one of the requirements is heavily tied to using client script.
I have experimented some with this and feel that ASP .Net stateful behaviour of the server side controls is really restricting when it comes to things like this.
If it is a simple dialog such as a login with username and password I can recommend that you do either a page method or a ashx handler that the javascript can communicate with, and then just build all the markup + server communication with your client side script.
But since you are building a more complex solution I would give you the advice that people already have suggested: Use UpdatePanels.
You can always hook up client scripts that run before the postBack (which shows the server side controls) is triggered, this client script can control if the postBack should fire or not etc. And you can also make the server side of the code invoke client side scripts when it have been rendered.
Things like this make you really appriciate ASP .Net MVC.

Rails: How should dynamic content be loaded? Via some sort of templates?

I'm building a survey system where a user can pick various types of questions. Each question should be loaded into the current page.
There are 6 different question types, each with different settings/form fields. You can also add multiples of the same type of question.
So should I have the form templates stored and then load them dynamically (I'm using jQuery)?
And if so, where should they be stored and how should they be called (they'd have erb in them)?
EDIT: For clarification, I know how to do the javascript stuff. I'm curious from the Rails side of things how this works. Would I create a bunch of partials for each question type? And how would I load just the partial content?
I suggest: http://railscasts.com/episodes/197-nested-model-form-part-2
And in the link, comment 57 claims to have it unobstrusive way here: http://github.com/thb/surveysays
But I'd avoid using ajax for such kind of feature: if it can be done client side, do it client side :)
You can make an AJAX request to the server and have jQuery completely replace the content in a certain, say, <div> with new HTML content sent back from the server.
Take a look at the documentation for jQuery.load: http://api.jquery.com/load
From the Rails side, yes, have the forms in partials that are sent back via AJAX, but can also be included in 'normal' HTML requests for folks that do not have JavaScript enabled.

ASP.NET Conversion to Fully AJAX Based Application

I am in charge of converting an ASP.NET web application into fully AJAX based application. I know Javascript and Jquery very well.
Initially I thought to point every anchor tag's click event to JS function and to call stuff via ajax and to populate the body and so on. I encountered a problem when it came to ASP.NET Form on every page and when there was need to make a post-back. I decided to point every Form tag's onSubmit event to a JS function to post stuff using ajax and to get results and I got to know this is not possible with ASP.NET as every time where is a button click, there will be post back so it's hard to let page know what button was clicked.
I then decided to use ASP.NET built-in AJAX controls to use with Forms which is pretty easy and worked like the way they should.
Now I am stuck with the question of which I should go with?
I like to be JS way because it's more customizable than AJAX.NET. I highly need your suggestions.
I don't see a problem in using ASP.NET Ajax. The scriptmanager and UpdatePanel controls will make you task easy and fast to convert to and ajax enabled website.
I am not sure what kind of customization you are looking for but you can still use js way whereever necessary. One another plus point with ASP.NET Ajax is it is well tested and used by thousands of sites and comes with lots of controls like in ajaxcontrol toolkit.
If you want to convert a web forms application completely to JavaScript coding, this is going to be really hard to do. It would be a lot easier to use the updatepanel control to make it look asynchronous to the user, as this doesn't break the server-side integration. But if you are using JS to post back to the server, then wipe the UI and replace it with the new one every time, that's going to be a lot harder.
Ideally, the best way is to use web services, call the web services through JS code (either JQuery or using the Sys.Net.WebServiceProxy ASP.NET AJAX object) to stream the data and you build the client in JS.
Let me know if you want more info...
HTH.

Categories