Highlight entire text inside text field with single click - html

I want to be able to just click inside a text field, so that it highlights all the text inside it (and possibly also copies it). Although, I'm satisfied with just getting it highlighted if that's possible with HTML only. Many people are using NoScript and such nowadays, so I'm trying to stay away from JavaScript etc.
TinyPic is one example which uses this little 'feature'.
Thanks for your help.

I'm pretty sure you need to use some javascript; no matter how trivial it might be.
For example; this does what you're asking:
<input type="text" value="Click Me to Select Text" onclick="this.select()">

in the head section add this script:
<script language="JavaScript">
function highlight(field) {
field.focus();
field.select();}</script>
And then for each field that you want to select all the text in when clicked, add this:
onClick='highlight(this);
I hope it works, try it by the way

Related

How to properly use same text sections across multiple html pages?

I am making help content documentation for an already made software (the kind of which opens in every software when you press F1 or navigate to the Help section in the menu bar). I am using simple html/CSS/js pages to do so.
There is a ton of the same text descriptions of various software properties that appear in more than one page. The idea is to make a single text source file, where all the text descriptions are located and then use some sort of referencing to that specific text section wherever necessary.
Kind of a similar to using a CSS stylesheet to apply styles over all of the pages, only this handles text instead of styles. This way I would be able to change text in only one file and it would apply everywhere it is used.
I ran across the html SSI method, but this only includes the entire html page and not just a specific text section the way I would like to. I would strongly avoid using different file for each text section.
Can anyone please point me into the right direction here?
I think that you can make a JavaScript function that contains the common texts and use this functions in your code whenever you need them, for this the JavaScript that you create should be an external file and you can reference it in every html page you need it.
For example, you can have one function that returns "Hello World" and set this to a "p" element with the id="title". So in every page where you have an element with the id title you can call your JavaScript function to set its text to "Hello World". Use this link to find out more about this topic:
http://www.w3schools.com/js/js_htmldom_html.asp
UPDATE: I did a little test, i created the following JavaScript:
function helloTitle(){
var text = "Hello World!";
document.getElementById("title").innerHTML = text;
}
And referenced it in some HTML pages like this:
<script src="commonText.js" type="text/javascript"></script>
After that i only need to call the function in the element i want it to modify:
<p id="title"><script>helloTitle();</script></p>
This is a solution if you are only using JS, CSS and HTML. There should be other ways to achieve this.
Hope this information could help you!
I figured out how to do it a little more comforatbly on a large scale using the html command https://www.w3schools.com/tags/tag_iframe.asp
in your main html file you do:
<p> <iframe src="Text.html" width="100%" height="300" style="border:1px solid black;"> </p>
and then with some basic html formating insert whatever text u want
<html>
<body>
hmm idk what i should put here. Test
</body>
</html>
there will also be some css formatting needing to be done before it look perfect, but if you want to make multi line blocks I think this is the easiest way to.

HTML: Why might an input with type=hidden appear after </HTML> on a web page?

I just had a look at html of my twitter page as part of learning HTML. At the end of the page I can see a lot of state as the value of a hidden input tag (the value appears to be in json form).
I see no obvious form associated with this, and it doesn't appear in the html request.
I wonder if anyone might be able to guess how/why these inputs and their values might be used.
</body>
</html>
<input type="hidden" id="init-data" class="json-data" value="
{"scribeMetrics":0,"environment":"production","wtfOptions":
{"dismissable":true,"connections":true,"pc":true,"limit":3,"
disabled":false,"display_location":"wtf-component"}
........ and so on.
If you look at this javascript file, you see that the init-data element is used
var a=$("#init-data").val(),
b=JSON.parse(a),
c=$.makeArray(arguments);
b.moreCSSBundle?using("css!"+b.moreCSSBundle,d):d()}if($("html").hasClass("debug"))
//and so on
If you want to know, why they used a hidden field and not standard javascript variables, you have to ask the guys responsible for this at twitter themselves ;). I see no obvious reason and the minified code doesn't make it easier to understand what's going on.

How to make anchor link focus the form field?

I have error messages in anchor tag. When you click on it, it should focus/take the cursor to the respective form field. It works in IE but does not work in FF or Chrome. Am I doing something wrong here?
I have a sample in jsfiddle. http://jsfiddle.net/JaaTK/
I don't want to use JavaScript to achieve this.
EDIT I will have to go JS route as there doesn't seem to be a better way.
If you don't want use javascript - you have to use “label” tag instead “anchor”, i.e. instead of:
Go to the first name
you can use:
<label for="firstName">Go to the first name</label>
Why not
Go to first name
I think is the only way.
"I don't want to use JavaScript to achieve this."
Then you are out of luck. Applying focus to an element is JavaScript's job.
UPDATE
So, based on your comment, I think you are asking the wrong question. I think you want to ask:
"Is there a way to make my error messages more accessible?"
The best way to handle that would be for your error messages to link to the form field's LABEL rather than apply auto-focus to the field. At least, that'd be the best way to handle things sans JavaScript.
Error Message
<label for="field1" id="fieldlabel1">Label</label><input id="field1" />

How to fill an HTML form with CSS?

I have an HTML form with radio buttons, check boxes, text fields and drop down lists.
Since I want user to fill everything in my form, none of the radio buttons and check boxes are checked and the text fields are empty.
I would like to write a CSS file that will fill the form with answers (I don't want to change my HTML file).
Is this possible ?
I would appreciate an example or any other idea ?
Thanks !
No, it isn't possible. CSS is for style, not markup, and changing the contents of an input field requires modification of the markup.
It sounds like you might want to consider JavaScript, which can be used to alter the contents of any element, including form elements.
Javascript is your best bet. If you want to fill in -sample- answers, however, like 'First Name' in the text area what would be labelled "First Name: " you can do something like <input type='text' value='First Name' name='emailForm'> and the value attribute will be filled in when the page loads.
You can use jQuery to accomplish what you want quite easily, using CSS-style syntax.
Here's a sample form:
<form ...>
<input name="firstName" />
<input name="lastName" />
</form>
And corresponding jQuery/JavaScript:
$(function () {
$("input[name=firstName]").val("John");
$("input[name=lastName]").val("Doe");
});
Should be easy enough to extend to a larger and more complex form. You can easily use classes or ids on the elements and in the jQuery selectors, as well.
CSS is for designing and styling the webpage. Although its capabilities have been exploited to pull of many tricks it is not a fix-all solution. What you need to do is pull the data you need to fill and put it in your fields.
You can do this two ways:
Use a server side language like PHP/ASP.Net to pre-fill this information.
Use Javascript/Jquery/MooTools or some other framework to fill it on the client-side, picking up the data from the server.
If the information is static then it is very easy, because you can just put this info as a part of the HTML content itself.
If this answer doesn't work for you, add more information to your question.

How to customize form styled by django-uni-form?

I'm using django-uni-form to style my form using the filter my_form|as_uni_form:
<form class="uniForm" id="my_form" method="post" action="./">
<fieldset class="inlineLabels">
{{ my_form|as_uni_form }}
<div class="form_block">
<input type="submit" value="Submit"/>
</div>
</fieldset>
</form>
It looks really good. But I need to customize it.
For example, one of the field "percentage" of the form is of the type IntegerField. It is being rendered as an <input type="text">. The problem is that the text box is really wide, I'd like to make it only 2 character wide. Also I want to add a percentage sign "%" right after the text box so that users know they if they put in the number "10" in the text box, it means 10%.
Is there anyway to do that with django-uni-form?
Thanks for your help.
You'll need to loop over the elements of your form and render the uniForm markup yourself. Either that, you can customize the look of each input based on an id or class.
What I'd do is look at the mark up it generates, and then loop over the elements generating that same markup and customize them. See the Django docs for more information.
I have the same question as yours. I think the length of the text input is easy to change via css. I'm more concerned about the custom html element behind the input, in your case percentage mark. I don't find an easy solution to it. Looks like either we have to mimick the way a field is rendered in django-uni-form template or write a filter of our own. I'm still waiting for a more elegant solution.