Automatically recognize the textfield on google.com - html

I'm developing a browser and I want to automatically insert a string in googles search field, when loading the page. The problem is, that it has no type="text". I've seen an approach to search for an element with name="q" (that's the name of the field), but it seems to be not very elegant, since it's possible, that the name changes over time.
Does anyone has a better idea?
THX

I just checked, when I call both "google.com" and "google.at" the text field has type="text":
<input id="gbqfq" class="gbqfif" name="q" type="text" [...]>
But: Searching for an input field with type="text" is just as brittle as searching for an input field with name="q": Google might add more input fields, rename them, do even more JavaScript magic, ...
If you just want to search for stuff, you cann use the following GET request: https://www.google.com/search?q=QUERY_GOES_HERE - This is probably a lot more stable than inserting text into text fields. (HT to Ethan Brouwer who mentioned this in a comment on your question).

Related

Displaying hint that characters are invalid during typing with html input

I'm building a form with Apache Freemarker that contains data for a data structure. For some reason I have to prohibit the character * from ever being submitted into one of the fields. I have been able to successfully forbid the character using my input field like so:
<input type="text" name="permission" id="permission" class="form-control" pattern="^[^\*]*" value="<#if permission??>${permission}</#if>"/>
However, I can still input the * character. This is still fine to me, but what isn't is that one only gets the message, that the input is invalid, once one clicks send. This looks like this:
This does not only not match my style, but the message is rather unhelpful. How do I
customize this box, if I even can.
make the hint appear, as soon as someone enteres a forbidden character

HTML5 pattern: Check text field start not start with blank space

Try check if input filed start with blank space, after testing e few hours and searching and testing a lot of patterns, found on internet, it doesn't work.
What i want: check if html5 input field start with character (no blank space), but in the text are blank spaces allowed.
At the moment the best solution i found, but it doesn't work:
<input type="text" class="naamveld" placeholder="Fullname" pattern="^\S+$" required>
Someone can help me with this 'simple' thing?
You should use a regular expression like this:
^[^-\s][\w\s-]+$
like it is explained in this question
According to your question, you said you wanted to remove all the whitespaces in the input, try this:
<input type="text" class="naamveld" placeholder="Fullname" required onkeydown="this.value = this.value.trim()" onkeyup="this.value = this.value.trim()">
If you try adding spaces at the beginning and end of the input, it will remove them.
How it works
The input has two attributes, (onkeydown and onkeyup) these functions will perform when the input receives a keyup or keydown, and will remove all whitespaces from the value of the input using this.value = this.value.trim()
If you want to learn more on how the trim() function works, you can go here.
First of all, again sorry for my bad english :-s
I want thanks everyone for all this useful info. When looking to the answers and solutions, with our help this is the solution (see pattern):
<input type="text" pattern="^\S.*$" ...>
Checked if input field started with blank space(s).
This is for me the best and simplest solution :-)

How to use HTML form validation - pattern attribute?

I can't seem to get the pattern attribute to work for the HTML form validation. I have seen a lot of tutorials and it all says the same and it works for them. Though I am using the same technique as the tutorials, I can't get it to work. For an example, please see the below code.
<label for= "firstname" id="firstname">First Name*</label>
<input type="text" name="firstname" pattern="[A-Za-z]" title="Only Alphabets" required/>
I want only alphabets to be inserted into this text box. When I insert numerals, it does ask to match the requested format which is only alphabets. But even when I enter alphabets it shows the message though it is supposed to let me submit the form. I tried all I can but can't seem to find a solution for this due my lack of knowledge. I would really appreciate if you could let me know how to enter only numbers into a field, only alphabets into a field, numbers and alphabets into a field using the pattern attribute for validation. Moreover, I was wondering whether the pattern attribute would be able to help me with this as well. For the National ID text box, I want the user to insert data in a specific format. Like this "A000000". An A in the first followed by 6 digits and if this format is not followed, then to display the message asking to match the requested format. Thank you so much in advance. (Please keep note that I am not using jquery).
Edit
May I please know how to add ' (apostrophe) along with the alphabets? Moreover pattern="[A-Za-z]+" wont let me insert spaces between words. How do I fix that?
The pattern field uses regular expressions. Try:
pattern="[A-Za-z]+"
For the national ID you could use:
pattern="A[0-9]{6}"

HTML - Lock default value in text area and user insert more info

Im not sure on how to explain this but, what I want to know is there if there is any way to "lock" just one part of an text area in a html form. Example:
<input name="example" type="text" id="example" valeu="__this part cant be modified__, and here user insert aditional info" />
And then I get this field value as like: "this part cant be modified + what user typed"
Thank you
I don't think you can, your best bet would probably to just append your default value to their input upon submission.
No, there isn’t, not for input elements, not for textarea elements.
You can however create an impression of such behavior, e.g. having some text and an input element on the same line and setting their style as similar as possible (setting all text, background, and border properties). Of course, the form data would still consist of the input value. And prepending the fixed text to it in client-side JavaScript would be possible but normally pointless, since it would be inherently unreliable and since you can simply make the form handler behave as if it got that string (i.e., make it have it as built-in data).

Can a user language change form values in html?

My application has a form with 2 submit buttons:
<input name="rating" class="Show" type="submit" value="Show answer">
<input name="rating" class="Skip" type="submit" value="Skip">
However I noticed some errors in GAE logs:
ValueError: invalid literal for int() with base 10: 'Voir la r\xe9ponse'
ValueError: invalid literal for int() with base 10: 'Sauter'
Basically it's the value of the form buttons, in French, whereas my app is in English.
How can a user change the form submit values? For example with google translate etc?
How can I handle this?
Yeah, that'll be Google Translate. It translates the text on the buttons as well. If you really want to prevent this, you'll have to make sure Google can't translate the text on the button. Note: these answers are not semantic HTML. Not sure if there's a cleaner method, I hope so, but this is what first springs to mind:
Method 1: hidden inputs
Since you're using buttons anyway, you might as well have them submit something. Put each button in its own form, add a hidden field, and use the value of the hidden field to determine what page to load next.
Downside: a lot of extra html, not really maintenance-friendly
Method 2: numeric value
Change the value of the buttons into something numeric, like 0 and 1. Hide the button's value with CSS and give the button a background image that shows the text. Load the page based on the numeric value.
Downside: very bad accessibility (screen readers, etc.), text on button won't be translated.
I really do hope there's better alternatives I haven't thought of yet.