Is there any way that we can hide variable value in html? I dont want user to see the values at any cost.
<input id="defaulterrormessage" type="hidden" th:value="${errorMsg}"></input>
The above code will only hide from web page but if you inspect then you can see the value.
No. Use AJAX to pull values from the server as needed instead of storing them in the HTML (or CSS as generated content values or JS as variables, since all those can be discovered).
Can you provide more information? What are you trying to accomplish? If this is a form and you are assigning values after a submit, I suggest a server side language like php or c#.
If you are doing something with these values on your current page you could also store your values in a session variable or cookie depending on what is needed.
There are two approaches:
1) Make the value accessible by the page, but stored outside the page
eg.
Stored in HTML5 localStorage, accessible via localStorage.getItem(value);
Stored in an external JSON file, accessible via Ajax
Stored in a cookie, accessible via cookie interrogation
etc.
2) Hide the encoded value in plain sight. Decode using javascript
eg.
Encode the value as ASCII
Encode the value as Base64
etc.
Related
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.
I am volunteering on a website-based project that is trying to make all pages fully operable JavaScript free before adding any JavaScript for enhancements, and I was asked to investigate whether or not a particular scenario could be handled purely through HTML/CSS.
What we have is a form that is populated to help us filter a list of tickets that are displayed on the screen after a page update through a GET action, which itself works fine, but the concern with the current implementation is that the URL cannot be made into a permanent link. The request, however, to keep the permanent link as minimal as possible, is to only send GET parameters for fields that are populated with something (so, suppressing GET parameters for fields that are blank) instead of having a different GET parameter for each form field on the page.
I have thought of several ways that could be done, most including JavaScript (example: create fields with ids but no names and a hidden field w/ name that uses JS to grab the data from the fields), but also one that would be a POST action with a redirect back to the GET with a human readable string that could be permanently used. The lead dev, however would prefer not to go through the POST/redirect method if at all possible.
That being said, I'm trying to make sure I cover all my bases and ask experts their thoughts on this before I strongly push for the POST/redirect solution: Is there a way using only HTML & CSS to directly suppress GET parameters of a form for fields that are blank without using a POST/redirect?
No, suppressing fields from being submitted in an HTML form with method of "GET" is not possible without using JavaScript, or instead submitting the form with a POST method and using a server side function to minimize the form.
What fields are submitted are defined by the HTML specification and HTML and CSS alone cannot modify this behavior and still have the browser be compliant with the standards.
No, you cannot programmatically suppress any default browser behavior without using some kind of client scripting language, like JavaScript.
As a side note, you say "JavaScript for enhancements", but JavaScript is not used for enhancements these days. And no one in the real world would except a decent front-end without the use of JavaScript. I would suggest you simply use JavaScript.
I do not think you can avoid Javascript here to pre process before submission to eliminate unchanged /empty form fields.
I'm not sure whether this problem is discussed before but I want o store a javascript object in cookie through javascript.
Basically my problem is I've a html form with few input fields. I want to take input from the fields and store the same values in a javascript object. This javascript object is only accessible until I'm in this page. But once I go to another page, my javascript object becomes null/undefined. So I thought I can store the javascript object somewhere from where I can get back the values I entered from the input fields. But I don't know how I should be able to do this.
Any help will be appreciated.
Thanks,
Rupam
Cookie is the way to go.
You can do something like :
Add the plugin: https://github.com/carhartl/jquery-cookie
Setting a cookie:
$.cookie("CookieName","CookieValue");
Clearing the cookie:
$.removeCookie("CookieName");
Accessing the value in the cookie:
var temp = $.cookie("CookieName");
My advise is to use a dedicated persistant storage lib such as : http://brian.io/lawnchair/ It does exactly what you are looking for (and even more).
I need to copy values from a form displayed in one HTML page (incoming.html) to another HTML page (outgoing.html) in a browser. What will be the best approach to this, I have tried using imacros but have not been able to figure it out. I believe there can be a javascript solution to the above. What can be the best approach, I need the feature in a prototype and hence efficiency does not matter.
The best option would be to use a server scripting language. You can pass values between two HTML pages in 2 ways.
First, storing them in cookies using Javascript. If cookies are not enabled, then it would be a problem.
Second, Passing Values through the URL like PHP, but this method is not very secure if your using information that you do not want the user to view.
For eg:
a href='something.htm?Something=Passing some variables'
You can fetch them in the next page using Javascript and display them.
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)