im triyng to solve this problem of generic code structuration in Jquery.
I have a listener who do something when an html listbox change, just like this:
<script>
$("#sdate").change(function () {
$.ajax({
url: 'test.php',
data: {
ref: '<?php echo $_GET['ref']; ?>',
fase1: $(this).val()
},
type: 'get',
success: function (d) {
$('.selector').html(d);
}
});
});
</script>
Some times the listbox sdate can be different, i mean, some times sdate could be like this:
<select id="sdate">
<option>option1</option>
<option>option2</option>
</select>
Other times could be like this:
<select id="sdate">
<option fase2="some_value">option1</option>
<option fase2="some_value">option2</option>
</select>
Depending on the aviability of the parameter fase1 the GET vars i will send via ajax will change, for example if is <option>option1</option> the ajax call will be:
$.ajax({
url: 'test.php',
data: {
ref: '<?php echo $_GET['ref']; ?>',
fase1: $(this).val()
},
type: 'get',
success: function (d) {
$('.selector').html(d);
}
});
But if the listbox is like <option fase2="some_value">option1</option> the ajax call have to be like:
$.ajax({
url: 'test.php',
data: {
ref: '<?php echo $_GET['ref']; ?>',
fase1: THE_VALUE_FASE2_ON_THE_OPTION_PARAMETER
},
fase2: $(this).val()
}, type: 'get',
success: function (d) {
$('.selector').html(d);
}
});
Im very new at jquery so this is making me some problems, thanks for any orientation of how to script this!
Why you don’t evaluate the fase2 or fase1 attribute before send?
like
$('#sdate').attr('fase1');this return the value of attribute fase1 on your jquery.Something like this ???
EDIT: i think now it s better.