Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to set text of input field using .value. After setting the value of input field, when I click on that field the text disappears. I don't want text to disappear.
The input html is as follow:
<input aria-invalid="true" aria-required="true" data-automation-id="address-form-firstName"
tealeafid="COAC2ShpAddrFirstName" name="firstName" initialvalue="" class="field-input field-input--
error field-input--primary" id="firstName" value="">
Setting the value of this input:
let name= document.querySelector("#firstName");
name.value = "First Name of user";
This html tag is present on Walmart website. Is there any solution?
If you want the text to be disappeared try placeholder property:
let name= document.querySelector("#firstName");
name.placeholder = "FirstName";
<input aria-invalid="true" aria-required="true" data-automation-id="address-form-firstName"
tealeafid="COAC2ShpAddrFirstName" name="firstName" initialvalue="" class="field-input field-input--
error field-input--primary" id="firstName" value="">
You should add an EventListener to your input
let name= document.querySelector("#firstName");
name.value = "FirstName";
name.addEventListener("click", function(){
name.value = "";
});
CodePen : https://codepen.io/abdelhedi/pen/qBEEEYw
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I have an html page that requires getting the value of an input when a button is pressed so it can be used as a variable in a link. For example, my website would detect "word" being written in the input and would redirect to the link "google.com/word" when the button is clicked. Thanks for any help in advance!
HTML Code:
<td><input value="Input text Here..."></input></td>
<td>Click this Button</button></td>
There is not way to get input value only using HTML... give your button an onclick attribute:
<td>
<a href='https://example.com/test/VALUEFROMINPUTHERE'>
<button id="click" onclick="click()">Click this Button</button>
</a>
</td>
and your input an ID:
<td>
<input value="Input text Here..." id="input">
</td>
and add JS:
function click() {
let val = document.getElementById("input").value
window.location.href = "https://www.google.com/search?q=" + val
}
All I'm doing here is geting the input's value, and changing the window's href to the wanted word, also making sure the word is being searched in google by adding the "https://www.google.com/search?q=" before adding the value of the input.
In this code, when the a tag is clicked, it triggers a JS function that grabs the value of the input with the id "value" and opens thee link with by concatenating it's value to the end of the URL with the window.open() function.
<input type="text" placeholder="Enter Text" id="value" />
Click Me
<script>
function openLink() {
let value = document.getElementById("value").value
window.open(`https://www.example.com/${value}`)
}
</script>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to create a html form with required input fields. but its not responding. below is the code
<div class="col-sm-6">
<label for="city" class="form-control">city
<input name="city" type="text" id="city" class="form-control" required>
</label>
<div class="invalid-feedback">
valid city is required
</div>
</div>
If by "not responding" you mean that a user can submit the form without entering a "City" value, it may be because you need a <form> element around form controls in order to allow browsers' default behavior for required inputs to work correctly.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
So, I have this html form which the user fills up with his/her info. There is the mobile number field.
I´d like to add the country code automatically, but hidden from the user (since it´s going to be just a local - geographic - marketing action, it´s a fixed code), so I can receive the mobile number with the country code added directly to the database.
All I need is that the form (or JS) adds the value "11" to the beginning of the mobile number without the user noticing it. The user writes "321-456789" and I will receive "11321456789".
How to code that?
Thanks!
You can use JS to prepend (kudos to Stephen P's amazing vocabulary) "11" to the value of the input field like so:
function append11(){
var mobilenumber = document.getElementById("phonenumber");
var front = document.getElementById("front").value;
mobilenumber.value=front+mobilenumber.value;
}
<input type="number" id="phonenumber"><input type="number" value="11" id="front" hidden><button onclick="append11()">
Append 11
</button>
In the example above, whatever you input, after clicking the 'Append 11' button, will add "11" to the front of the value. You can configure this to submit a form like so:
function append11(){
var mobilenumber = document.getElementById("phonenumber");
var front = document.getElementById("front").value;
mobilenumber.value=front+mobilenumber.value;
alert(mobilevalue.value);
}
<form action="something" method="GET">
<input name="phonenumber" type="number" id="phonenumber"><input type="number" value="11" id="front" hidden><button onclick="append11()">
Submit
</button>
</form>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
If a user of my website inputs a value into an html text box and clicks on a submit button..
how can I transfer/use their value to javascript so I make a calculation based on their input.
Also how can I display their value on the site?
Thanks!
((New to javascript and stackoverflow))
You should have something like this in your HTML
<input name="searchTxt" type="text" id="txt" class="searchField"/>
And something like this in your JavaScript
var the_value_i_am_looking_for = document.getElementById('txt').value;
Note that the txt is the id of the input tag, and we use that same id to identify the element in JavaScript.
The variable the_value_i_am_looking_for should hold the value that you will use to make your calculation.
Example:
<input id="cost" type="number" />
<input type="button" onclick="calculate()" value="Enter a value" />
<div id="valueEntered" > </div>
<div id="afterTax" > </div>
<script>
function calculate()
{
valueEntered.innerHTML = " You entered : " + cost.value;
afterTax.innerHTML = " After tax : " + cost.value * 1.3;
}
</script>
You meant something like the following? It's a input box and a button. Once the button is clicked, the user input in the input box will be displayed below the input box and the button.
<input id="foo"/>
<button onclick="document.getElementById('bar').innerHTML = document.getElementById('foo').value
" type="button">Click me</button>
<div id="bar"></div>
</code>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
<input name="input1" id="input1" type="text" value="" class="problem">
<input name="input2" id="input2" type="text" value="" class="hidden">
I'm trying to populate a hidden text input (e.g. input#input2) field with the current value from another text input field (e.g. input#input1) (un-submitted) using jQuery. I've sourced this jsfiddle doing exactly what i require but with a drop down field. And i was wondering if anyone is able to point me in the right direction?
EDIT: Sorry if i wasn't clear, the jsfiddle works perfectly but i'm trying to use a text field instead of a drop down to populate the other field.
i always handle this by storing that value in a variable:
var yourText = document.getElementById("input1").value;
and then just plug it into the hidden field:
$('#input2').val(yourtext);
here's your hidden field:
<input id="input2" type="hidden" />
$("#my_form").submit(function(event){
var visibleInputVal = $("#input1").val();
if(visibleInputVal != ""){
$("#input2").val(visibleInputVal);
}else{
alert("you need to provide a value for input 1");
event.preventDefault();
}
});
<form id="my_form">
<input type="text" value="" id="input1" />
<input type="hidden" value="" id="input2" />
<input type="submit" value="Submit" />
</form>