Currently I am working on a piece of javascript to copy a link plus the option the user has selected within the select tag.
The variable I assign in the javascript remains undefined. Is there a way to make this code work? I do not wish to use the ID attribute with a loop unless this can be applied into my PHP script (in which I echo the select tags, because I'm showing database results, whenever a result is shown, it will also show a select tag). This link shows a simple example of what I made so far: http://jsfiddle.net/b31au78v/
Here is my code:
<table>
<tr>
<th>Name</th>
<th>Gender</th>
</tr>
<tr>
<td>Hank</td>
<td>
<select onChange="getValue()" class="ddlEval">
<option>Select an option...</option>
<option val="gender.php?=male">Male</option>
<option val="gender.php?=female">Female</option>
</select>
</td>
</tr>
<tr>
<td>Jeff</td>
<td>
<select onChange="getValue()" class="ddleval">
<option>Select an option...</option>
<option val="gender.php?=male">Male</option>
<option val="gender.php?=female">Female</option>
</select>
</td>
</tr>
</table>
<script>
function getValue() {
optVal = this.value;
if(optVal != "Select an option...")
{
window.prompt("This is the link that's going to be coppied: ", "localhost:8080/" + optVal);
}
}
</script>
I guess I need to replace "this" with something else, but it is only to show what I actually want to happen.