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
Related
I have a scenario and I will really appreciate any help. As shown in the image,
I have only multiple select box on the left where there are numbers and on the right this is text box, what I want to do is, when ever user clicks on the house numbers, it should come to the right text-area box, and will be able to append the values, from the text area as well.
Get the selected value with the apropriate handler (#input, #change, etc.) and then push it in some array inside your data();
Finally, bind this variable with the right-hand text-area.
Obs: once you didn't show the code, I tried help you using high level steps.
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.
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.
I found a jQuery plugin that allows me to highlight my text with a color which works perfectly. But now I need to get the highlighted text selection and place it in a text box.
I found this code which is exactly what I'm looking for although it doesn't pick up my color highlight as a selection.
This is the code I found and want to use is at this link http://www.codetoad.com/javascript_get_selected_text.asp#highlight2
As I suspected, the plugin "only" wraps text in a span. To access that text, you can use standard jQuery selectors. Basically, it works like this:
// the plugin generates new <span> elements with class="highlighted".
// You fetch all those with $('.highlighted.'). Then you get their text
// content by calling .text() [1]:
var text = $('.highlighted').text();
// Access your <textarea>, where you want to put the text into. Either
// use an ID element and use $('#id-of-textarea'), class or other means.
// to get the 1st one, use the ':eq(0)' jQuery selector (':eq(1)' for the
// second and so on) [2]. Then set the text with the jQuery .val() call [3]:
$('textarea:eq(0)'.val(text);
In your question you link to getSelection() method and its relatives. Those are good, if you want to access text selected by the user via mouse.
[1] http://api.jquery.com/text/
[2] http://api.jquery.com/eq-selector/
[3] http://api.jquery.com/val/
I am trying to set value to a hidden column. Previously i have achieved this by doing:
var bc = $("select[title='Broadcast Channel']").val();
$("select[title='Execution Channel']").val(bc);
This works fine as I am able to get the column which exist in html source.
Now I am trying to set value to a hidden column which I have hidden in Sharepoint 2010 list setting. And I am not able to find it under html source (e.g. <input type=hidden....>).
How can I set value to this hidden column?
Not sure if the following method will be acceptable to you, but here goes...
In sharepoint, make the input field non-hidden. Instead, make it invisible at document.ready() using JQuery. If the input field is given a specific ID/class name, you can get a reference to the same, and set the text (using text() function), or for more complex situations, consider enclosing it all in a div.
Best Regards,
Gopal Nair.
In share point make the field as text input and then using jquery make it hidden and then set the value. try something like
$('input[type="text"][title="abc"]').attr('type','hidden').val("abc");
There is a common problem that if an element is hidden from back end code, normally it is simply not rendered in the html generated. Elements that needs to be manipulated at the front end need to be shown but hidden using html or js code.