Still having problems here so I have an example that closer resembles what I'm trying to do.
http://www.ttmt.org.uk/
So I have a select menu thats adds a div which contains another select menu. The contents of the second select menu in the div is determined by the option selected in the first menu.
The problem I'm having now is I need to capture the value selected in the second menu in the div
Code:
$$ = $("<div class='selectDiv'></div>").appendTo('#contents');
$$.append(
$('<form />').html(theMenu).change(function(){
var index = $(this).parent().index();
alert(this.value);
})
)
It's currently alerting 'undefined', is this because it isn't available when the script is calling it?
HTML
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>untitled</title>
<style type="text/css" media="screen">
*{
margin:0;
padding:0;
}
#wrap{
width:500px;
margin:50px auto 0 auto;
}
.selectDiv{
background:red;
height:100px;
margin:10px 0 0 0;
}
.selectDiv .divSelect{
margin:20px;
}
</style>
</head>
<body>
<div id="wrap">
<form method="" action="">
<select id="addDiv">
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>
</form>
<div id="contents">
</div><!-- #contents -->
</div><!-- #wrap -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="code.js" type="text/javascript"></script>
</body>
</html>
jQuery
Code:
window.one=
'<select class="divSelect">'+
'<option value="One-One">One-One</option>'+
'<option value="One-Two">One-Two</option>'+
'<option value="One-Three">One-Three</option>'+
'</select>';
window.two=
'<select class="divSelect">'+
'<option value="Two-One">Two-One</option>'+
'<option value="Two-Two">Two-Two</option>'+
'<option value="Two-Three">Two-Three</option>'+
'</select>';
window.three=
'<select class="divSelect">'+
'<option value="Three-One">Three-One</option>'+
'<option value="Three-Two">Three-Two</option>'+
'<option value="Three-Three">Three-Three</option>'+
'</select>';
$('#addDiv').change(function(){
if((this.value) == 'One'){
theMenu = window.one;
}
if((this.value) == 'Two'){
theMenu = window.two;
}
if((this.value) == 'Three'){
theMenu = window.three;
}
//
$$ = $("<div class='selectDiv'></div>").appendTo('#contents');
$$.append(
$('<form />').html(theMenu).change(function(){
var index = $(this).parent().index();
alert(this.value);
})
)
})
Bookmarks