How to grab value of pre and put in input? [duplicate] - javascript

This question already has answers here:
Jquery Setting Value of Input Field
(7 answers)
jQuery change input text value
(6 answers)
How to set value of input text using jQuery
(7 answers)
set value of input element with jquery
(1 answer)
Closed 5 years ago.
I am trying to get the value of the pre tag. I inserted the value based upon a drop down into the pre tag. How would I grab the content of the <pre> and put it into the <input>? I can grab the content, but am struggling setting it as value for the <input>. Below, I have an example of what I have done.
JQUERY
var $temp = $('#Changeinfo').text();
alert($temp);
$('#Details') = $temp;
HTML
<div class="form-group">
<label class="control-label" for="Details">Details</label>
<div contenteditable="false" name="DetailID" id="DetailID"><pre
value="26" id="Changeinfo"> Do this based on selection
</pre>
</div>
<input class="form-control" type="text" id="Details" name="Details" value="">
<span class="text-danger field-validation-valid" data-valmsg-for="Details" data-valmsg-replace="true"></span>
</div>

Related

Updating value of input html using javascript fails [duplicate]

This question already has answers here:
HTML Input is not updating value attribute on change
(3 answers)
Modifying "value" attribute of "text" input not working using JavaScript
(1 answer)
Closed 3 years ago.
I have a simple html:
<td><input type="text" style="border:none;" size="12" id="titleId" name="title" value="333"></td>
and I use the code below to update the value of the input:
document.getElementById('titleId').value = "999";
However, when I click "inspect element" the value is still "333", but on the page it shows "999".
I need to update the value to "999" for pdf printing purposes.
How can I update the values using js?
In addition to #Phil's Comment, this is how you can change attribute's value via javascript
function test(){
document.getElementById("in").setAttribute("value", "999");
}
<input id="in" value="333"/>
<button onclick="test()">Click Me</button>

How to set a value to a hidden type input from javascript [duplicate]

This question already has answers here:
How to set the value of a input hidden field through JavaScript?
(5 answers)
Closed 5 years ago.
I am working with jsp. I want to set a value from JavaScript to HTML hidden type input in order to pass the value to another page.
This is my HTML code:
<form id="reg" method="post" action="/questionnaire.jsp">
<input type="hidden" name="userId" value="123">
<button id="submit" name="sr-buttobmitun">Submit</button>
</form>
JavaScript is like:
<script>
var userId = "123";
</script>
If you give the hidden input an id, you can then query the DOM for that element and set the value, like so:
document.getElementById('userid').value = '123';

Which attribute will stop users changing input data but allow jQuery to modify? [duplicate]

This question already has answers here:
What's the difference between disabled="disabled" and readonly="readonly" for HTML form input fields?
(7 answers)
Closed 7 years ago.
I have seen people recommending
<input name="input" readonly="readonly">
and
<input name="input" disabled="disabled">
But which of these two will:
Stop users changing the value
Allow jQuery to update the value
Use readonly, because disabled will also prevent the field from being submitted.

Can I save the value of a textbox? [duplicate]

This question already has answers here:
Get the value in an input text box
(13 answers)
Closed 8 years ago.
I have one text box and have written "ABC" in the text box, but I want to obtain the text using jQuery
<input type=text value="ABC">
But when I use jQuery's .html() it returns null
Here's a FIDDLE
<input type="text">
<span></span>
$('input').keyup(function() {
$('span').text($(this).val());
});
or
$('input').keyup(function() {
$('span').html($(this).val());
});

Getting an input field's type using Javascript [duplicate]

This question already has answers here:
Finding the 'type' of an input element
(4 answers)
Closed 9 years ago.
Please disregard this. There was an error in my script and I was looking on here for 15 minutes.
How do you find the type of an input field only using Javascript?
Per say you have these input field:
<input type="checkbox" name="confirm" id="confirm" value="Y"/>
<input type="text" name="firstName" id="firstName" />
How do you find the those field's input type?
It's as simple as:
var type = document.getElementById("confirm").type
Plain Javascript:
var type = document.getElementById('confirm').type;
jQuery:
var type = $('#confirm').attr('type');

Categories