I was googling around and saw a tutorial on YouTube that uses JavaScript to auto select options based on the select value.
The JavaScript code looks like this:
$("select[value]").each(function() {
$(this).val(this.getAttribute("value"));
});
And the code that is in the HTML is this (after PHP gets the data)
<select name="group" id="group" value="4">
<option value="1">Administrator</option>
<option value="2">Member</option>
<option value="3">Developer</option>
<option value="4">Moderator</option>
<option value="5">Donator</option>
</select>
The value in the select is supposed to tell the JavaScript what is to be selected, but it’s not working for me, help me please? (I’m new to JavaScript/PHP/MySQL)
That code uses the jQuery library. Given you haven’t tagged your question with jQuery, I suspect maybe you don’t realise that it is needed and haven’t included the jquery.js file?
Add this:
(To load it from Google’s CDN.)