Theoric question on HTML - html

is it possible via html to recall a HTML file (template) recall it and just change the value of PHP variable. And by the same way, this template position itself (with css) without any change?
Example: You want to display different objects to sell and the template is set graphically (photo + name + price) and you want to put another one just beside it.
If yes, by Javascript? or else?
Thanks

Using jQuery is very easy.
(1) Link your CSS earlier in the main HTML so when your template loaded the css will automatically applied.
(2) Add jQuery script like <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script> or you can download jQuery yourself and use yout own path.
(3) Assume you have <div id="containner"></div> to populate the template later.
(4) When the document load, button click or whenever you want to trigger to load the template simply call $('#containner').load('/path/template.html'); this is jQuery javascript code. the .load() method is an Ajax call to your template file.
(5) Any PHP variables in the template file will be evaluated and will produce html only since at server side.
(6) The returned template will populated in the containner div.

use ajax, the Javascript runs on the client browser can call a server side script and switch page content without refresh the page.

Related

How to get form data value from html and show on other html page

I am working on a html page with an input bar. How can I get the form data from this page to another html page with a iframe? Because I need to embed the search result from other site but I want to show on my site new page. I just guess should use iframe. But I don't know how to get data and add in page address field.
You have several options here:
1) If your form uses GET method, then all the text data from the form will be passed to next page (which is set up as an "action" attribute of the form) in URL (like www.example.com/?name=John&lastname=Doe). After that, you can extract data from this URL using code from this StackOverflow question and put it inside HTML element using Javascript as well like it is done here
2) Whatever server language you use, you can get query variables from there and put them to the page before sending it to the client. In case of PHP, check this example. NB: don't forget about security.
3) You can temporarily store text in localStorage API of the browser. Simply set the value before submitting the form and then get it on the next page.
iFrame would be inefficient and not needed here.

Get HTML element using JSP

I am new to Java EE. In my application, I have a HTML page containing a text area filled with some information.
I also have a form for the user. Once he submits the form, I use a servlet to process the information.
Finally I need to forward the Result from the servlet to the same HTML page and update it in the existing textarea.
I have done creation of HTML page, submitted the form to servlet.
I am now stuck on how to access the textarea in the HTML page to update my result.
I googled a lot but everywhere people forward the result of servlet to JSP page and create a fresh HTML page using "out" object.
I need to use the same textarea of my HTML page to update the result. Please help me on achieving this.
Thanks in advance.
There are two ways to do this.
Server-side rendering. You can re-draw the whole page, with a normal form submit. In this case you would put something in request scope in the servlet and then access that in the JSP when you draw the textarea. Note that you are not accessing the HTML textarea in the JSP - the JSP runs server-side code to generate HTML markup, but you are not accessing the browser DOM directly.
This might look like:
servlet: request.setAttribute("textareaContent", varWithTextareaContent)
JSP: <textarea>${textareaContent}</textarea>
Client-side rendering Instead, you could make an AJAX post request with jQuery (there are some plugins to help with this). In this case, your servlet would not forward to a JSP for HTML rendering - it would directly return a JSON object like {"textareaContent": ...} , and you would handle that client-side in your AJAX callback. In this case you would be accessing the textarea in the browser DOM directly, in Javascript (not JSP).

Jquery or json load data without refreshing page and add into html tags

I get some data on html/php page from database. And I edit it. But I want that data to change automatically without refreshing when I edit and click submit button. I have read that I must use json. But I can't add json values into html tags.
How can I do it ?
If you could not understand me, see this video.
You can use javascript to fetch the json file and manipulate the DOM accordingly. The example you provided uses jquery. Jquery provides a couple of ways to retrieve json data with ajax calls. This is all documented very well. See https://api.jquery.com/jquery.get/

No refresh with core-drawer-panel

I have a little problem with Polymer.. but i have no idea for fix it...
when i go to my website:
http://toi-meme-tu-c.hol.es/polymer-tutorial-master/team/
and i click on the "i" for information (Case Scaroboy) ALL the drawer-panel refresh... how fix-it without javascript?
I have tried to include the drawer-panel into a php page but it's not an issue...
So I asked here, because im a begineer with Polymer...
thanks, Scaroboy
It must use Javascript i think because no core element so far build to replace the content directly. To load new content inside the main panel you will need ajax request which you can use core-ajax element (on v0.5) or iron-ajax element (on v0.8) but you will need to write Javascript function to handle the ajax response.
Or you can create your own element wrap ajax element with replace content inside container that you can pass through attribute.

How can I send information from one html page to another?

I want to create an html page which contains a text box. When I am given input and the Enter key is pressed, I want it to go to another html page and display the typed keyword.
How can I do this?
I think you need to use a server-side scripting language to facilitate the manipulation of the inputted data on the form, so that it gets "saved" and displayed in the other html page. I suggest you try reading about PHP, and then turn to handling information in Web Forms...just a thought!
You can use Javascript for that. Check this Tutorial : How do I pass variables between two pages? (GET method)