문제

I have an edit form that loads values from a database. Some of the values are supposed to trigger a div to show and it does when they are changed. However I would like the option value that loads the $mt value to trigger on page load. This is what I have so far. Sorry, my Jquery skills are quite sad.

$('#selectEnum').load(function(){
    if($(this).find('[value="corporate"]'){
        $(#corporate).show();
    }
});

echo "<p>Please select member type: <select id=selectEnum class=\"box\" type=\"text\" name=\"coll_type\"><option value=\"$mt\">$mt<option>";
    $q = "SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
        WHERE TABLE_NAME = 'members' AND COLUMN_NAME = 'm_type'";
    $r = mysqli_query($dbc, $q);

    $row = mysqli_fetch_array($r);

    $enumList = explode(",", str_replace("'", "", substr($row['COLUMN_TYPE'], 5, (strlen($row['COLUMN_TYPE'])-6))));
    foreach($enumList as $value)
        echo "<option value=\"$value\">$value</option>";

    echo "</select></p>";   
?>

UPDATE: here is the rest of the Jquery associated with this select input:

 $.enumList = {
  'family' : $([]),
  'institutional' : $('#institutional'),
  'corporate' : $('#corporate'),
  'other' : $('#other')
};

$('#selectEnum').change(function() {
  // hide all
  $.each($.enumList, function() { this.hide(); });
  // show current
  $.enumList[$(this).val()].show();
});
});
도움이 되었습니까?

해결책

You can do this:

$(document).ready(function() {
    if($('#selectEnum').val() == 'corporate')
        $('#corporate').show();    // Don't forget to surround the div id with quotes
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top