• Post Reply Bookmark Topic Watch Topic
  • New Topic

Populating HTML via .dat, .txt or excel file  RSS feed

 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extremely new - so go easy

Read through a bunch of posts and this may be a server side request and if so I'd really (really) appreciate a link where to go.

I have a HTML form on a page that I'd like to update via a file rather than via the HTML code. Can this be done via JS?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Need more info. Why can't you change the HTML code?
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill, welcome to Java Ranch!

JavaScript typically runs inside the browser on each client's machine, so unless the file is also on the client's machine, JavaScript can't read it. Actually, reading files off the file system is not something JS is really good at either, so even if the file was on the client's machine, it wouldn't be straightforward to read. It would probably involve some tricky JS, and maybe configuring the browser to allow it.

What you want is something that can build HTML dynamically on the server side, like JSP/servlets in the Java world, or PHP, Ruby On Rails, etc. There are many choices.
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Welcome to the Ranch.

Need more info. Why can't you change the HTML code?


Hi Bear - I can access the HTML but the page itself is a template where a handful of text strings get replaced and the template is uploaded to a new folder (site).

My hope was to change out a (.dat, .txt) file, upload it to the new folder and not have to touch the HTML
(does that make sense?)
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:Hi Bill, welcome to Java Ranch!

JavaScript typically runs inside the browser on each client's machine, so unless the file is also on the client's machine, JavaScript can't read it. Actually, reading files off the file system is not something JS is really good at either, so even if the file was on the client's machine, it wouldn't be straightforward to read. It would probably involve some tricky JS, and maybe configuring the browser to allow it.

What you want is something that can build HTML dynamically on the server side, like JSP/servlets in the Java world, or PHP, Ruby On Rails, etc. There are many choices.


(Bear & Greg - thanks for the Welcome too!)

Greg - one would think a google search would give me a 1,000 or so hits but either I'm asking wrong or there's no easy answer (please don't point me over to StackOverflow.com, that site is way beyond my level (for now))

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We'd never do that!

But we need more info on what it is that you are trying to accomplish. Again, why can't you just change the HTML? Is it a case where you want to generate the form dynamically based on other information? Why the need for some "other file"?

If not, then what?
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:We'd never do that!

But we need more info on what it is that you are trying to accomplish. Again, why can't you just change the HTML? Is it a case where you want to generate the form dynamically based on other information? Why the need for some "other file"?

If not, then what?


(in my feeble mind, this is how I see it being done - I'm open for suggestions)

Kill you with detail now...

I have a Lead Generation page setup as a template (sandbox: www.kwmds.com/mobile - video plays auto so click off on start). The whole page is standard except for 3 pieces.

At the bottom there is a DIV with a background image (logo), another DIV with several lines identifying an agent and the form up top has a hidden “ID” field - all three change based on agent.

The page may have to be reproduced a hundred times for different agents and I was hoping to be able to FTP the Index file and image folder along with a “.dat/.txt” file that would change the 3 dynamic pieces.

(edit):

I could edit the HTML for each agent as an order came in but I thought the .dat file scenario had the least margin of error
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, that sounds tailor-made for a server-side templating engine such as JSP or PHP. You would set up a JSP or PHP page once, and when the page is served, the dynamic portion of the page would be created on-the-fly for each agent.

This all assumes that you can deploy this on a capable server. Do you have any leeway on how the app will be hosted?

If not you need to find out what the capabilities of your hosting server are.

And yes, this could also be done on the client with JavaScript, but that'd be the approach of last resort to me if a server-side template can be used instead.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact, please read this article which explains what templating is all about. The article focuses on JSP, but the templating concept also applies to PHP.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, in lieu of a file which contains the dynamic data, have you considered the more common approach of using a database?
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Also, in lieu of a file which contains the dynamic data, have you considered the more common approach of using a database?


YES YES YES - this was my original thought! If I had a DB in the root directory, could each of the templates reference and pull their data via that file?

Only problem is... I have (less than) NO IDEA how to make it work!?!?!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you looking for something quick? Or are you looking to use this to learn how to write Java web apps?

Also, could you answer the server question? It makes a huge difference to what approaches you can take.
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Are you looking for something quick? Or are you looking to use this to learn how to write Java web apps?

Also, could you answer the server question? It makes a huge difference to what approaches you can take.


Always looking to learn "anything" new however, also want to get this page done (and duplicatable) so we can launch the product.
(ps: I’m a sales guy by trade and everything I know is self-taught, so I’m sure my syntax is less than desirable)

My hosting (dedicated godaddy - from what I understand) is a hybrid. Pretty sure it is Linux based but can also handle the ASP (Microsoft) side of things.
Is that what you were looking for?
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doing some more research - dangerous I know...

Along the KISS (keep it simple…) lines; couldn’t I fill in a HTML DIV right from a XML file that resides on the server?

(is that an easier “code” than setting up a SQL DB and retrieving info from it?)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ASP is another server-side templating technology, but it's proprietary to Microsoft. It's certainly an option for you, but Microsoft stuff isn't a focus of these forums.

To be honest, for "quick and dirty" I'd say that setting up a JSON file (rather than XML), digesting it through Ajax, and using JavaScript and jQuery would be the shortest distance between the points. It's just not the way I'd go for a long-term solution.

It's unlikely, from what you've said so far, that your server is Java enabled. That pretty much means one of PHP (almost always enabled on most servers), ASP (dead-end Microsoft proprietary crap), or JavaScript with Ajax and jQuery.

All require a somewhat steep learning curve in skill set.
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would believe the server is JAVA enabled?

I was messing around with the XML idea and added this to a test page - http://kwmds.com/mobile-beta/test.

Rather than acting on the button's Onclick event, why can't the file be loaded right into a DIV on page load?

(or is this a ASP technology and not JS?)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can use Java, then servlets/JSP is another option on the table.
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:If you can use Java, then servlets/JSP is another option on the table.


so sorry for my ignorance but what scripting language am I using on the http://kwmds.com/mobile-beta/test site?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To respond to the button click? That's JavaScript.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!