d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Little Problem Jquery > And Maybe Easy For You :|
Prev123Next
Add Reply New Topic New Poll
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jan 13 2014 12:48am
Quote (nonNo @ Jan 13 2014 05:30am)
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




Code
var ar = new Array(v, w, x, y, z);

for(var i = 0; i < ar.length; i++) {

var imgs = "img" + ar[i];

$("#imgs").click(function(){
$("#Big").text("");
$("#Big").append(ar[i]);
});

}



try this, im not 100% sure, but jquery might not like the concatenation in the id retrieve
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 13 2014 02:42am
i'have try this solution too

ar=new Array(v,w,x,y,z);
har=new Array('v','w','x','y','z');
var i=0;
for (i=0;i<=har.length;i++){
$("#img"+har[i]).click(function(){
$("#Big").text("");
$("#Big").append(ar[i]);
});
}

it work's 90%...i mean that the problem is in the last command.
if i try to force ar[0] for example, it work's. If i try to write ar[i] it doesnt works...seems that the function doesnt see the [i] :S
really i dont know the reason....var i got global scope :S

Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Jan 13 2014 12:19pm
Quote (nonNo @ Jan 13 2014 02:42am)
i'have try this solution too

  ar=new Array(v,w,x,y,z);
  har=new Array('v','w','x','y','z');
  var i=0;
  for (i=0;i<=har.length;i++){
  $("#img"+har[i]).click(function(){
  $("#Big").text("");
  $("#Big").append(ar[i]);
  });
  }

it work's 90%...i mean that the problem is in the last command.
if i try to force ar[0] for example, it work's. If i try to write ar[i] it doesnt works...seems that the function doesnt see the [i] :S
really i dont know the reason....var i got global scope :S


really don't have too much experience with js, but it'd look something like this, not gonna verify syntax so probably will need edited

$array[] = 'urlone.jpg';
$array[] = 'urltwo.jpg';
$array[] = 'urlthree.jpg';

$(function(){
setInterval(Transitioner, 3000);
});

function Transitioner() {
$i++;
if($i > 2) $i = 0;
document.getElementById( 'slide1' ).style.display = 'none';
document.getElementById( 'slide2' ).style.display = 'none';
document.getElementById( 'slide3' ).style.display = 'none';
document.getElementById( 'slide' . $array[$i] ).style.display = 'inline';
}

too tired to add in the clicks, going to bed
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jan 13 2014 01:37pm
Quote (nonNo @ Jan 13 2014 08:42am)
i'have try this solution too

  ar=new Array(v,w,x,y,z);
  har=new Array('v','w','x','y','z');
  var i=0;
  for (i=0;i<=har.length;i++){
  $("#img"+har[i]).click(function(){
  $("#Big").text("");
  $("#Big").append(ar[i]);
  });
  }

it work's 90%...i mean that the problem is in the last command.
if i try to force ar[0] for example, it work's. If i try to write ar[i] it doesnt works...seems that the function doesnt see the [i] :S
really i dont know the reason....var i got global scope :S


var has i has global because you put it outside your for loop, write it like this :

Code
for(var i = 0; i.....){
}


next thing is semantically that
Code
.append(ar[i]);

should work

its the same thing as:

Code
document.getElementById("Big").innerHTML += ar[i];


one thing i did notice is you dont have the javascript initialize around your code :

Code
$(document).ready(function(){

});


put that around all of your javascript

another thing is, i would avoid using caps on your div tag ids
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 13 2014 01:48pm
Huston we got a problem

har=new Array('v','w','x','y','z');
ar=new Array(v,w,x,y,z);
for (var i=0;i<=har.length;i++){
$("#img"+har[i]).click(function(){
$("#Big").text("");
alert(i);
});
}

6,6,6,6 ALWAYS 6 every image.....the problem is there :|
my array got 5 img and he return everytime the number of the beast XD
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 16 2014 05:43am
All the problems above are been resolved....now i got another little problem :(

I have Index.html with 2 button and 1 div

in Text.html i got 2 div named IT and ENG

i want to do this little thing

press Button one and see into the div in Index.html the text of the div IT placed in text.html
press Button two and see into the div in Index.html the text of the div ENG placed in text.html

i think an Ajax called is a must...but im little confused how use it



Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Jan 16 2014 12:02pm
Quote (nonNo @ Jan 16 2014 05:43am)
All the problems above are been resolved....now i got another little problem :(

I have Index.html with 2 button and 1 div

in Text.html i got 2 div named IT and ENG

i want to do this little thing

press Button one and see  into the div in  Index.html the text of the div IT placed in text.html
press Button two and see into the div in Index.html the text of the div ENG placed in text.html

i think an Ajax called is a must...but im little confused how use it


Ajax or something like

$('#content').load('text.html');

Then you'd need to grab inner html on whatever div
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 16 2014 12:31pm
Quote (0n35 @ 16 Jan 2014 20:02)
Ajax or something like

$('#content').load('text.html');

Then you'd need to grab inner html on whatever div


:unsure:

im in this situation:
INDEX.html

<input type="button" value="ITA" id="ita">
<input type="button" value="ENG" id="eng">
<div id="result"></div>

<script type="text/javascript">
$.get("Text.html", function(){

});

$("#eng").click(function(){

});
</script>
---------------------------

TEXT.html
<body>
<div id="engdiv">HELLO WORLD</div>
<div id="itdiv">CIAO MONDO</div>
</body>

i want click on the button with id eng and see HELLO WORLD into the result div :|
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jan 16 2014 01:42pm
heres what i suggest:

use an XML Doc

use an XMLRequest

indext.html:

Code
<html>
<head>
<script src="jquery/jquery1.10.2.js"></script>
</head>

<body>
<input type="button" value="ITA" id="ita">
<input type="button" value="ENG" id="eng">
<div id="result"></div>


<script>


function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
xmlDoc=loadXMLDoc("testing.xml");


var engdiv = xmlDoc.getElementsByTagName('div')[0];
var itdiv = xmlDoc.getElementsByTagName('div')[1];

$("#eng").click(function(){
$('#result').html(engdiv.childNodes[0].nodeValue);

});


$("#ita").click(function(){
$('#result').html(itdiv.childNodes[0].nodeValue);

});
</script>
</body>
</html>



text.xml (make sure this is xml):
Code
<?xml version="1.0"?>
<body>
<div id="engdiv">HELLO WORLD</div>
<div id="itdiv">CIAO MONDO</div>
</body>



heres what it does:

http://quelynn.com/dev/code_snippet/ajax_example_nonNo/index.html

This post was edited by AkuuZ on Jan 16 2014 01:42pm
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 16 2014 01:47pm
i havent fg to sent to you :(
Go Back To Programming & Development Topic List
Prev123Next
Add Reply New Topic New Poll