When we are trying to get the html of div using the below code it is having all the data except the text which I am entering in the textarea or input field
var mywindow = $(printDiv).html();
mywindow will have all the html except textarea text, radio button values or inputfield.
I have looked into this question but using clone is giving any text at all.
The thing to remember is that .html() does exactly what it says: it gives you the HTML currently in the DOM within that node. But the thing is, content entered by the user, and more generally the content of HTML input fields, is not a part of the HTML. Entering text into a textarea or checking a checkbox or radio button doesn't change the HTML one bit. It does update the internal memory representations of the individual DOM nodes, but this isn't represented in the HTML.
Whenever you want to get content from an input element on the page, you have to use .val() instead of .html(). The .val() function also does what it says: it gets you the value of the input field.
To get the text in a textarea you have to use .val() in JQuery. e.g.
var text = $('#textarea_id').val();
console.log(text);
The second line logs it to the console so you can check it works.
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 am confused, I used jQuery to $("#display").html(value) toward my html input with id ="display" but nothing appears in the html input.
However we can see the value in the element : "32" (see picture)
Any idea why the value doesn't appear?
I try to replace input by span and it works well.
image : example
thanks,
Thomas
You cannot set the innerHTML value of an input element (which is what jQuery is doing when you use $.html()). Instead, you need to use $.val().
Try using $("#display").val(value) instead.
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
Is there a way using angular or just javascript to get the user input text not using HTML input boxes? For example when a user clicks on a paragraph he will be able to change its text without a text area popping so he could input. I tried focusing on angular ngHide element( a input HTML) but with no success. It only focused on the element when its showing.
Try contenteditable introduced in HTML 5.
Try Fiddle.
<p contenteditable="true" onfocus="alert(this.textContent)" onblur="alert(this.textContent)">
Enter Name
</p>
But there is. contenteditable is an HTML attribute that makes divs and cells editable. you can make a directive in angularjs to use that, but beware of the caveats that it introduces.
Take a look at x-editable. It will suit your needs, i think.
I put together a jsfiddle to demonstrate an issue where I'm loosing <textarea> values when using jQuery.html() or jQuery.replaceWith().
http://jsfiddle.net/wsams/Hxehg/2/
If you append a bit of text to the <textarea> and then click the click me text, see the console, the textarea value is stripped.
I'm expecting the values of each <textarea> to be preserved. Any ideas on how to do this or what's going on? Thanks