I am attempting to input text/variables the user has enetered into textboxes into certain words that already exist in the text area. An XML file has been pulled into the textarea so I'm wanting to modify certain keywords.
How can I do this? This is all going to be done locally. The browser pulls a file selected by user into text area, and then text fields modify this text area.
you want to change the text in the textarea based in the text in another input, so this is what i could do at glance with jquery
$('#input').change(function(event) {
var newText = $('#textarea').val().replace(/textToReplace/g, $(this).val())
$('#textarea').val(newText)
}
You listen to the change event in the inputs that contain the words you want to replace, and then change the textarea value after replacing that words in the current text.
Related
Could anyone tell how to select portion of text in textarea and copy it to clipboard by using javascript? I know how to select all text in textarea and copy it? My question is that when we use mouse to select part of text in textarea, how to copy it to clipboard.
How about this
(on)select save the start and end position of the selection to the input element itself.
event.target.lastSelection = { start:startpos, end:endpos};
and use the (on)blur event to do something like
event.target.setSelectionRange( event.target.lastSelection.start, event.target.lastSelection.end )?
So I have this json format of
{
questionID: int
studentAnswer: "String"
}
The studentAnswer field is populated from whatever is inputted in an HTML textarea. If I input something in one line only, the json is valid. But if I input something where i press enter to go to the next line, the json becomes invalid. I need the studentAnswer to be able to hold the input value with multiple lines. How can I fix this?
The problem is that multiline json's aren't valid. Since you're using a textarea, perhaps you can resize the textarea, restrict it, sanitize its inputs, or change the form type.
Ultimately, you want whatever the user input to be one line. Try this option out:
Is it possible to disable textarea's multiline option?
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 have two textarea elements. I want to mirror the input given to one text area which has focus to another textarea. Please note that this is not equivalent to copying the values, since one textarea may already have some input which I do not want to copied. Thus only the input given to text area should be forwarded onto second textarea.
Something on the lines of:
$('#textarea1').keyDown(function(e) {
textarea2.sendCommand(e.keyCode)
});
Is something like this available in javascript?
If i have an input type=text and am viewing it on a mobile device, if I press inside the input and hold down on the text (let's say it's a url), the entire url won't be selected. Only a single word will be. I want to be able to easily select the entire text and then copy it. Is there a way to do this in css or html? I can select all the text with javascript but then trying to touch down to copy does the same thing, only selects a word.
for instance:
<input type="text" value="http://foo.bar">
I click in the middle and only "foo" gets selected. I want to select all the text so it's easy to copy
Here you go:
$('input').focus(function() {
this.select()
});
$('input').click(function() {
this.focus();this.select()
});
Implemented here: http://jsfiddle.net/4XJDW/