I have two textareas in jsp page the values entered in first textarea value should be displayed in next text area frequently using jQuery.
Here is the code I've tried so far
function getMsg()
{
document.getElementById("chatBox").value =
document.getElementById("messageBox").value;
document.getElementById("messageBox").value=""; }'
}
$(function() {
$("#test1").keyup(function() {
$('#test2').val(this.value);
});
});
Is this you were expecting
$(document).ready(function () {
$('#firsttext_area').keyup(function () {
$("#sectext_area").val( $('#firsttext_area').val());
});
});
Demo in fiddle
In jquery you can try the following
$("#textAreaOne").keyup(function() {
$("#textAreaTwo").val($("#textAreaOne").val());
});
Update:
It sounds from your comment that you want to append text to the second text area, you would have to create a button that the user will click to fire your event
Create a button, for example
<button id="chatButton">Chat</button>
Then wire the buttons onclick event to perform the append functionality, for example
$("#chatButton").click(function() {
$("#textAreaTwo").val($("#textAreaTwo").val() + "\n\n" + $("textAreaOne").val());
});
This is what the exact answer for my question. I tried with this and it is working.
<script>
var tempMsg;
function getValue()
{
var userMsg="Me: "+document.getElementById("messageBox").value;
var chatMsg=document.getElementById("chatBox");
tempMsg=chatMsg.innerHTML+=userMsg+"\n\n";
}
</script>
You can implement this by event onChange.
Related
I have this div:
<div id="flaw">
<img id='flaw1' src='images\flaw1.png'>
<img id='flaw2' src='images\flaw2.png'>
<img id='flaw3' src='images\flaw3.png'>
<img id='flaw4' src='images\flaw4.png'>
<img id='flaw5' src='images\flaw5.png'>
<img id='flaw6' src='images\flaw6.png'>
<img id='flaw7' src='images\flaw7.png'>
<img id='flaw8' src='images\flaw8.png'>
<img id='flaw9' src='images\flaw9.png'>
</div>
I'm trying to make 3 buttons. Every time 1 random button should be good. the other 2 bad buttons should make 1 of the images appear.
If you click the wrong button 9 times, all images will be visible and you would lose the game.
First I tried putting all images in an array, but I kept failing...
Eventually I ended up with this;
$(document).ready(function () {
var buttons = $("#buttons img");
var flaw = $("#flaw img");
window.onload = function () {
flaw.hide();
};
buttons.on('click', function () {
$("#flaw1").show();
})
});
All it has to do now is show the first image when someone clicks a button.
And show the next image when someone clicks it again and again and again.
Until all 9 images are visible.
But I could figure out how to loop through the images on every click.
Can anyone help me?
you can do something like this
var flaws = $("#flaw img");
buttons.on('click', function () {
flaws.each(function(){
if ( ($(this).is(":hidden") ){
$(this).show();
break;
}
});
})
For further refernces check
http://api.jquery.com/hidden-selector/
http://api.jquery.com/each/
I want to have words inside a Jlabel text that are clickable, and I want to register a MouseListener for each word or getting the clicked word (otherwise). The image below demonstrate what I want. Is this possible ?!
No, you can only make the whole JLabel clickable. But you can put several JLabels next to each other of course, making only a few clickable (and different in appearance).
You could also use HTML, e.g. in a JEditorPane, and make certain words clickable via HTML, if that suits your needs. I found something about that here, and this is how it could look like for you:
JEditorPane jep = new JEditorPane("text/html", "Click <a href='pdf'>here</a> to display a PDF file. For more information click <a href='info'>here</a>.");
jep.setEditable(false);
jep.setOpaque(false);
jep.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent hle) {
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
if (hle.getDescription().equalsIgnoreCase("pdf")) {
// display PDF
} else if (hle.getDescription().equalsIgnoreCase("info")) {
// display information
}
}
}
});
I am usign GWT2.3.
We developed CustomPager by overriding SimplePager.
We override createText() method such a way that we are showing string like "Page 1 of 4" using following code
public String createText() {
if(searchRecordCount%pageSizeForText == 0){
totalPages = searchRecordCount/pageSizeForText;
}else{
totalPages = (searchRecordCount/pageSizeForText) + 1;
}
NumberFormat formatter = NumberFormat.getFormat("#,###");
return "Page "+formatter.format(this.getPage()+1) + " of " + formatter.format(totalPages);
}
Now I want to use TextBox for CurrentPage so that user can enter page Number in textBox. (Functionality GoTo entered pageNumber)
createText() returns string so I cant user textBox ;) + Can't provide css
How can I do this ? Is there any way to solve this problem? Workaround if any or Sample code
There are two ways how to achieve this:
1.) Use HTML code to create a TextBox:
In the createText() function you can create the textbox manually by using HTML code (better use SafeHTML templates for avoiding XSS):
String textbox_str = "<input type='textbox' name='goto'>";
However you have to write code for handling the actual event (i.e. ChangeEvent) and call setPage() of your SimplePager using JSNI.
2.) Add TextBox widget to SimplePager and override constructor:
SimplePager is basically a Composite which adds ImageButtons in its constructor for the forward and backward links.
You can extend SimplePager add a TextBox and override the constructor to add the TextBox between the forward and backward ImageButtons.
Is it possible to get the height of a 'text' field from mysql?
Or the number of linebreaks would also work!
I have a table which fetches the 'text' field from my mysql database.
The background image of the table is sort of a container...
I want the background to change to another (taller) background if the text is vertically high!
Possible, if so how?
Thanks
UPDATE: I am not going to use word wrapping...
In your query you can count how many instances of '\n' are found. You can do this in javascript or php as well. This wouldn't be totally accurate though if you're word wrapping.
How to do it with php
Alternatively... to grab the height with javascript:
document.getElementById('mytable').clientHeight;
Very difficult, as you're never going to be able to predict font size with 100% certainty (Users could have enlarged text in their browser, for instance, or be using a different font).
If you want to make 100% sure, you would need to use Javascript to measure the actual size.
Otherwise, for most cases, as #Chris Klepeis says, counting the line breaks should work.
I think this will be help but i used textarea here and i test it will be working fine u just need apply it on table.
<textarea data-adaptheight rows="3" cols="40" placeholder="Your input" style="padding: 16px; line-height: 1.5;"></textarea>
<script>
(function() {
function adjustHeight(textareaElement, minHeight) {
// compute the height difference which is caused by border and outline
var outerHeight = parseInt(window.getComputedStyle(el).height, 10);
var diff = outerHeight - el.clientHeight;
el.style.height = 0;
el.style.height = Math.max(minHeight, el.scrollHeight + diff) + 'px';
}
var textAreas = [].slice.call(document.querySelectorAll('textarea[data-adaptheight]'));
textAreas.forEach(function(el) {
el.style.boxSizing = el.style.mozBoxSizing = 'border-box';
el.style.overflowY = 'hidden';
var minHeight = el.scrollHeight;
el.addEventListener('input', function() {
adjustHeight(el, minHeight);
});
window.addEventListener('resize', function() {
adjustHeight(el, minHeight);
});
adjustHeight(el, minHeight);
});
}());
</script>
How can I select a tab as if it was clicked by clicking on a button?
I have googled and looked at all the actions but there are just just so many... :(
Anyone know off hand?
Thanks in advance!
Add an action listener to the button that calls setSelectedComponent, or setSelectedIndex on the JTabbedPane.
I'm not sure what you mean about the button, but you might be looking for setSelectedComponent or setSelectedIndex.
If your jtabbedpane's name is mytabbedpane it goes like this:
mytabbedpane.getSelectedIndex();
which returns the int of that tab (0,1 .. n) or
mytabbedpane.getSelectedComponent();
which returns the String of the tab's name ("Firts tab","Second tab",...).
If you want to use the "getSelectedComponent()" for boolean logic you should write something like:
if (mytabbedpane.getSelectedComponent().equals("First tab")) {
//code here
}
and for the "getSelectedIndex()" one is of course:
if (mytabbedpane.getSelectedIndex() == 0) {
//code here
}
Double click on button, put the follwing code
JTabbedPane.setSelectedIndex(1);
Tabs starts from 0 to N left to right order
Try this code:
tabbedPane.addTab(tabName, component);
int count = tabbedPane.getTabCount();
tabbedPane.setSelectedIndex(count-1);