I have this working code which I'm using to set placeholder values for username and password fields:
<script>document.getElementById("user_login").setAttribute("placeholder","Please enter your Email Address");</script>
and
<script>document.getElementById("user_pass").setAttribute("placeholder","Please enter your Password");</script>
Now I'm trying to apply this to a 3rd box which has the input ID #memb_password_send-1-email-input but this isn't a straight up element, it's an input field and using this ID (as above) obviously doesn't work.
Here is a picture of console:
What would be the correct way to target this field with placeholder text?
Same method used to provide placeholder for username and password fields would work in this case as well as those are input fields as well. Just make sure that when you are writing this code in in-line script, do this after that input box has rendered i.e. after it's markup so that element is available to get selected.
Related
I have a text input correctly set in html.
When this method is called pressing a button:
this._searchInput.setAttribute("value", "pippo"+Math.random());
console.log(this._searchInput.value);
It works correctly, and input text fields shows the string with random number.
Alas, if I type once inside the input text field, all subsequent calls to set value are ignored. Method is called since console outputs the same value visible in text field.
Any suggestion? Is there a reson why after typing in a text field value doesn't get updated by code anymore?
I have already found a similar question but it went unaswered: Cannot set dynamically text value in input after typing
You are setting the value attribute of the input, not setting the input's actual value.
This is the line of code you want:
this._searchInput.value= "pippo"+Math.random();
I can't seem to find anything similar to this right now, but I am pretty sure I have seen something like it before.
I am currently able to use either input or textarea html tags and the placeholder attribute to get something close to what I want, but I also want to provide the user the ability to copy the placeholder text and enter/paste it in the same box as an entry. Is this possible?
An use case would be a place holder of a common directory path:
box1#mtk:/path/to/data/20180202_TextFile.txt
I want the user to be able to copy and paste "box1#mtk:/path/to/data/" into the box so they just have to change the text file name.
I can't force value to be the placeholder because I don't want users accidentally submitting forms without modifying all fields.
So is it possible to have selectable / copyable placeholders?
No you have to choose between placeholder and value. I would just use value in combination with a script that enables the button when all the fields are different from their default value or prints an error message if they are not eg:
if(document.getElementById(“value1”).value !== “DEFAULT TEXT” && document.getElementById(“value2”).value !== “DEFAULT TEXT” && ......) {
document.getElementById(“submit”).disabled = false;
}
As part of my websites setup I am using a login form that is generated using a shortcode; because of this I cannot add the placeholder attribute in the HTML of the form so my only option is to add it using JS/jQuery. Unfortunately this is an area of website development that I am unfamiliar with.
I need to add 2 different placeholder texts, one for the 'Email' field and another for the 'Password' field. To make this easier you can view the form here:
https://members.argentumfx.co.uk
The top field is for the 'Email' placeholder and the bottom field is for the 'Password' placeholder.
Here is an example of what I'm looking for:
View Placeholder Mockup
#user_login is the ID of the Email field; #user_pass is the ID of the Password field.
Please can someone provide me with some JS/jQuery to achieve this task?
Without any libraries:
document.getElementById("user_login").setAttribute("placeholder","Email Address");
If you have jQuery, you can use the attr method to set the placeholder attribute on each input.
$(function() {
$('input#user_login').attr('placeholder', 'Email Address');
$('input#user_pass').attr('placeholder', 'Password');
});
I have Got a div with two text area fields in it and , i have got a list of names where ; if you click on a name from the list it fills the first text area with the name and second text area with surname. This is done via jquery.
I need to save all the content of the div with the values in to mysql and for this reason I have tried .html(), .text(), get().innerHTML, get(), content(), but even though it gets the html , it doesnt not get the text area html with value.
You need to grab the text area fields individually and then use .val() on them to get whatever will be entered in the field.
ok i found a way to do it , when i mentioned that you click on a name from the list it sets the value of the text area; i used ,val(); , but instead i am now using .text(); and it allows me to get the value of it when i use .html(); to get the entire content with the form values. It may not be the best way but it does the job , I am open to suggestions
I have a JSP registration form in my site. Also I have a text box with placeholder="opt" and id="ext" in my JSP registration page which is an optional field. On clicking submit button the value of placeholder is submitting to the database on leaving the optional field blank. But I want to clear the value of text box on leaving it blank. I've tried the below methods. But those methods are not working in my case.
document.getElementById("ext").value="";
document.getElementById("ext").placeholder="";
document.getElementById("ext").setAttribute("placeholder","");
I've also tried the same methods with jQuery. That also is not working.
Can anybody suggest a solution.
You can prevent the value of placeholder entering into DB b having a condition on servlet (business logic) i.e the page handling the DB operations.
Check on servlet like as below:
if(request.getParameter("<Parameter name Here>").equals("<Plaeholder value>"))
{
// set value of <Parameter name Here> nullhere
// Do insert option here
}
The solution will be valid untill you wil change the placeholder's value.