I have a problem with passing one of the html elements to jQuery. I know that with attr() we can access attributes. However, I feel like I'm something wrong.
This is my simple jQuery function:
<script type="text/javascript"> function test(value) { alert(value); } </script>
I have a dynamic list created by a 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 someone clicks on items in a list that shows their item in my inbox, for example. However, this code did not work for me.
onclick="test(<script>this.attr('title').value</script>);"
How can I send the value of the title attribute of my function from the onclick attribute?
Thanks in advance.
source share