d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Little Problem Jquery > And Maybe Easy For You :|
123Next
Add Reply New Topic New Poll
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 9 2014 12:29pm
<p id="par"></p>

<input type="text" id="testo"/>
<input type="button" id="btn1" value="Insert in BOX"/>

<script type="text/javascript">
var txt=$("#testo");
$("#btn1").click(function(){
$("#par").append(txt);
});
</script>


I have this simple <p> 1 button and 1 input text.

i want write something into the textbox, and when i press the button i want see the text into my <p></p>

how can i do?

this code work 50% that's mean that if i write HELLO WORLD into the textbox and i press the Button the script copy the textbox plus the text into the <p> :(
i want only the text into the <p>
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Jan 9 2014 12:46pm
1. You need to set var text inside the click function.
2. You need to call val() on $("testo"); this returns the text inside the input

This should work...

Code
$("#btn1").click(function(){
var txt=$("#testo").val();
$('#par').append(txt);
});


This post was edited by labatymo on Jan 9 2014 12:47pm
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 9 2014 01:03pm
Quote (labatymo @ 9 Jan 2014 20:46)
1. You need to set var text inside the click function.
2. You need to call val() on $("testo"); this returns the text inside the input

This should work...

Code
$("#btn1").click(function(){
var txt=$("#testo").val();
$('#par').append(txt);
});



number 1....nothing to say B)
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jan 11 2014 12:35pm
incase you want to do this with regular javascript,this should word (i didnt test it tho)


Code
<p id="par"></p>

<input type="text" id="testo"/>
<input type="button" id="btn1" value="Insert in BOX" onclick="change_val()"/>

<script>
function change_val(){

var testo_val = document.getElementById("testo").value;


document.getElementById("par").innerHTML += testo_val;

return false;

}

</script>
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 12 2014 12:06pm
Now i give u another problem about Jquery about slideshow this time.



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My slideshowz</title>
<script language="javascript" type="text/javascript" src="Js/jquery-1.10.2.js"></script>
<script language="javascript" type="text/javascript" src="Js/jquery_cycle.js"></script>
<link href="Css/Style.css" rel="stylesheet" type="text/css">

</head>
<body>
<div id="Big">
<img src="Img/1.jpg" />
<img src="Img/2.jpg" />
<img src="Img/3.jpg" />
<img src="Img/4.jpg" />
<img src="Img/5.jpg" />
</div>

<div id="Small">
<img src="Img/1a.jpg" id="imgv" />
<img src="Img/2a.jpg" id="imgw" />
<img src="Img/3a.jpg" id="imgx" />
<img src="Img/4a.jpg" id="imgy" />
<img src="Img/5a.jpg" id="imgz" />
</div>


<script type="text/javascript">
var v='<img src="Img/1.jpg"/>';
var w='<img src="Img/2.jpg"/>';
var x='<img src="Img/3.jpg"/>';
var y='<img src="Img/4.jpg"/>';
var z='<img src="Img/5.jpg"/>';

//Slideshow Jquery normal
var ciclo = $(function(){
$('#Big img:gt(0)').hide();
setInterval(function(){$('#Big :first-child').toggle("slow").next('img').toggle("slow").end().appendTo('#Big');}, 3000);
});


$("#imgv").click(function(){
$("#Big").text("");
$("#Big").append(v);
});

$("#imgw").click(function(){
$("#Big").text("");
$("#Big").append(w);
});

$("#imgx").click(function(){
$("#Big").text("");
$("#Big").append(x);
});

$("#imgy").click(function(){
$("#Big").text("");
$("#Big").append(y);
});

$("#imgz").click(function(){
$("#Big").text("");
$("#Big").append(z);
});
</script>
</body>
</html>


I have try to make myself a simple slideshow for homework.
It's work at 80%, i mean that if i refresh the page the slideshow work correctly with fadein-fadeout, if i click on the little thumbnail i can change image, but after halfsecond that i have clicked on thumbnail image fadeout and all slideshow got broken :(

Is it possible stop the slideshow for X seconds the slideshow and after X seconds it autorestart?
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jan 12 2014 03:47pm
Not 100% sure what part your wanting to time out, but you can use:

Code
setTimeout(function() {
// stop the slide show for 3 sec
}, 3000);


3000 = 3 secs (its in milliseconds)

is your homework requiring you to use jquery?

do you know basic javascript?
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Jan 12 2014 08:52pm
that's kind of an odd way to go about doing this, why not throw those values in an array, then for each 3000ms go to the next in array and also have a check if it is maxed out to start from the beginning then have side buttons just go forward/backward one and restart the timer when doing so
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jan 12 2014 09:12pm
Quote (0n35 @ Jan 13 2014 02:52am)
that's kind of an odd way to go about doing this, why not throw those values in an array, then for each 3000ms go to the next in array and also have a check if it is maxed out to start from the beginning then have side buttons just go forward/backward one and restart the timer when doing so


yea i dont quite understand why he did it this way. just appaneds the image, instead of already having the data on there and just sliding through.

heres the slider i made ( its slightly more complicated then that slider, as it uses an xml file for all of the information. its still in development, so im going to be changing a few things, but anyways:


http://quelynn.com/dev/slider/slider.html

im using basically a posiition system i created so you know what slide your on and what slide you need to jump to.
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 12 2014 10:51pm
Quote (AkuuZ @ 12 Jan 2014 23:47)
Not 100% sure what part your wanting to time out, but you can use:

Code
setTimeout(function() {
      // stop the slide show for 3 sec
}, 3000);


3000 = 3 secs (its in milliseconds)

is your homework requiring you to use jquery?

do you know basic javascript?



yes we can use javascript and jquery for make that.
i havent think about array....is it easier with them? :O and btw i dont konw how set it for be usefull :S
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 12 2014 11:30pm
ar=new Array();
ar[0]=v;
ar[1]=w;
ar[2]=x;
ar[3]=y;
ar[4]=z;

for (i=0;i<=ar.length;i++){
$("#img+ar[i]").click(function(){
$("#Big").text("");
$("#Big").append(ar[i]);
});
}

i have try this for replace all .click in all thumbnail....but doesnt work :S

$("#img"+ar[i])
$("#img+ar[i]") i have try both sintax

This post was edited by nonNo on Jan 12 2014 11:32pm
Go Back To Programming & Development Topic List
123Next
Add Reply New Topic New Poll