I have a problem in passing one of html element to jQuery. I know that with attr() we can access to attributes. Nevertheless I feel I do something wrong.
This is my simple jQuery function:
<script type="text/javascript">
function test(value) {
alert(value);
}
</script>
I have a dynamic listbox which has been created by foreach loop:
<select multiple="multiple" name="factors1" id="main_factors" style="width: 200px; height: 200px;">
<?php foreach ($array as $option): ?>
<option onclick="test(<script>this.attr('title').value</script>);"
id="<?php echo $option[0]; ?>"
title="<?php echo $option[2]; ?>"
value="<?php echo $option[0]; ?>">
<?php echo $option[1]; ?>
</option>
<?php endforeach ?>
</select>
I want when somebody click on items in list box its item show in my messagebox for example. However this code did not work for me.
onclick="test(<script>this.attr('title').value</script>);"
How can I send title attribute value to my function from onclick attribute?
Thanks in advance.