• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

js not running...

Two list boxes show some static data. Js included is expected to revise their content stored in an array fro each and also respond upon a click on these list boxes. It doesn't work.

Question: Could you possibly see what is wrong with it?

Thank you.
userinput.htm
designpalette.css
jquery-1.2.6.min.js
jquery-1.7.2.min.js
0
Mike Eghtebas
Asked:
Mike Eghtebas
  • 2
3 Solutions
 
Tom BeckCommented:
There's a couple of things wrong with this:
<script type="text/javascript" src="jquery-1.2.6.min.js">

				

		alert("here");

		

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

		var groupNames = ["Group 1x", "Group 2x", "Group 3x", "Group 4x"];

		$.each(groupNames,function(){

		$('#group').append('</option>').text(this);

		});



		$.each(subgroupNames ,function(){

		var subgroupNames = ["Sub G  1x", "Sub G 2x", "Sub G 3x", "Sub G 4x"];

		$('#subgroup').append('</option>').text(this);

		});



		$('#group').click(function(){alert('group is clicked');});

		$('#subgroup').click(function(){alert('subgroup is clicked');});

		});

	</script>

Open in new window


This should get you closer:
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>

	<script type="text/javascript">			

		alert("here");

		

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

		var groupNames = ["Group 1x", "Group 2x", "Group 3x", "Group 4x"];

		$.each(groupNames,function(){

		$('#group').append('</option>').text(this);

		});


		var subgroupNames = ["Sub G  1x", "Sub G 2x", "Sub G 3x", "Sub G 4x"];

		$.each(subgroupNames ,function(){


		$('#subgroup').append('</option>').text(this);

		});



		$('#group').click(function(){alert('group is clicked');});

		$('#subgroup').click(function(){alert('subgroup is clicked');});

		});

	</script>

Open in new window

0
 
BuggyCoderCommented:
do this in your head section:-

<head>
	<title>Survey</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link href="styles/designpalette.css" rel="stylesheet" type="text/css" />
	
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
	
	<script type="text/javascript">
				
		alert("here");
		
		$('document').ready(function(){
		var groupNames = ["Group 1x", "Group 2x", "Group 3x", "Group 4x"];
		$.each(groupNames,function(){
		$('#group').append('</option>').text(this);
		});

		$.each(subgroupNames ,function(){
		var subgroupNames = ["Sub G  1x", "Sub G 2x", "Sub G 3x", "Sub G 4x"];
		$('#subgroup').append('</option>').text(this);
		});

		$('#group').click(function(){alert('group is clicked');});
		$('#subgroup').click(function(){alert('subgroup is clicked');});
		});
	</script>
</head>

Open in new window

0
 
Tom BeckCommented:
This is the corrected code to get the new list items appended:
alert("here");

		

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

		var groupNames = ["Group 1x", "Group 2x", "Group 3x", "Group 4x"];

		$.each(groupNames,function(i){

		$('#group').append('<option>' + groupNames[i] + '</option>');

		});


		var subgroupNames = ["Sub G  1x", "Sub G 2x", "Sub G 3x", "Sub G 4x"];

		$.each(subgroupNames ,function(i){


		$('#subgroup').append('<option>' + subgroupNames[i] + '</option>');

		});



		$('#group').click(function(){alert('group is clicked');});

		$('#subgroup').click(function(){alert('subgroup is clicked');});

		});

Open in new window

0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now