[Solved] HTML get value of select popoulated by PHP array


There is a missing " after the javascript function and your code could be modified a little like this – to use event rather than rely upon names or ids

<select name="category" id="_category" class="_cateogry" onchange="submitTheForm(event)" >
    <option value="">Please select</option>
    <?php foreach ($categories as $contents ) {?>
        <option value="<?php echo $contents->id;?>" selected="selected"><?php echo $contents->name;?></option>
    <?php }?>
</select>

function submitTheForm( event ) {
    var value=event.target.value;
    var text=event.target.options[event.target.options.selectedIndex].text;
    console.log('%s -> %s',value,text);
}

1

solved HTML get value of select popoulated by PHP array