I previous recieved help with a problem, getting a multiple option select form to create new inputs, depending on how many were selected. The code below is what ended up working for me (credit goes to Peter Bailey)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(function()
{
$('#test')
.after( '<div id="option-inputs"></div>' )
.find( 'option' ).each( function()
{
var $option = $(this);
$option
.data( '$input', $( '<span>' + $option.text() + ': </span><input><br>').appendTo( '#option-inputs' ).hide() )
.bind( 'toggle-input', function()
{
var $input = $option.data( '$input' );
if ( $option[0].selected )
{
$input.show();
} else {
$input.hide();
}
})
.bind( 'click', function()
{
$(this).siblings().andSelf().trigger( 'toggle-input' );
})
.trigger( 'toggle-input' )
;
})
;
});
</script>
</head>
<body>
<select id="test" multiple="multiple">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</body>
</html>
I don't know jQuery so I need help with one last tweak. I need to be able to limit which options selected create new boxes. So, if an option of value -1 or 0 is selected, a new textbox is not created. Anything else does.
Also is there any way to have other select forms trigger this to one to update? In regular javascript you'd use onChange="" and a function to update it. The reason for this is that the select table is dynamically populated, based on the input of the previous select table. If you go back and make changes to the previous select table, it doesn't update the jQuery, the previous inputs remain.
Thanks for the assistance!