d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Ajax,jquery..array. > Urgent This Time :| And Fast Answer
Add Reply New Topic New Poll
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 13 2014 02:46pm
I got 2 files.

the first is Prov.html with this command

<select id="provincie">
<option id="ve">Veneto</option>
<option id="lo">Lombardia</option>
</select>

<script type="text/javascript">
$.get( "pv.html" ,function(data){
});
</script>

the second is Pv.html with these 2 arrays

<script type="text/javascript">
var ven=new Array("Belluno","Venezia","Treviso");
var lom=new Array("Milano","Brescia","Pavia");
</script>

i have done these.
If i select Veneto from the selectbox in the first file i have to put all the elements of the array ven into another select box always in the file one
If i select Lombardia from the selectbox in the first file i have to put all the elements of the array lom into another select box always in the file one

but i dont know the sintax for link the things :(

my teacher will be happy if i can do this alone :)

This post was edited by nonNo on Jan 13 2014 02:46pm
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jan 13 2014 03:05pm
im not sure what your trying to do exactly
Member
Posts: 9,318
Joined: Mar 17 2007
Gold: 2.20
Jan 13 2014 03:19pm
i got 2 dropdownlist, the first got 2 elements veneto and lombardia, the second contain the major city of these 2 region.

if i select veneto in the other dropdownlist or selectbox call it as u want :) i have to see belluno venezia and treviso,
if i select lombardia in ther other dropdownlist or select box i have to see milano brescia pavia.

but these town are in an array and these array are in another files.

so i have to link the 2 files and with a call of ajax i have to fill my dropdownlist with the correct town :)
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jan 13 2014 05:13pm
the problem is that get function only returns the data in a certain format i believe.

what you want to do is put all of your javascript in a .js file and use ajax just to load that file in as a script type.
here:

prov.html:

Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript" type="text/javascript" src="jquery/jquery1.10.2.js"></script>
</head>
<body>

<select id="provincie">
<option>Select Province</option>
<option id="ve">Veneto</option>
<option id="lo">Lombardia</option>
</select>


<div id="show_city"></div>


<script>
$.ajax({url:"pv.js",dataType:"script"});
</script>

</body>
</html>



pv.js :

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


var ven = new Array("Belluno","Venezia","Treviso");
var lom = new Array("Milano","Brescia","Pavia");



function show_prov(){
var sel_val = $("#provincie").val();
if(sel_val == "Veneto"){
$("#show_city").html('');
for(var i = 0; i < ven.length; i++){
$("#show_city").append(ven[i] + "<br/>");
}
}


if(sel_val == "Lombardia"){
$("#show_city").html('');
for(var i = 0; i < lom.length; i++){
$("#show_city").append(lom[i] + "<br/>");
}

}

};

$("select").change( show_prov );
show_prov();




});
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll