设计:
    学院:下拉框1  clg
    专业:下拉框2  mjr
    年级:下拉框3  grd
    班级:下拉框4  cls
功能:
    clg选项改变时以下三个下拉框的值都要改变,其中mjr的值是从数据库表中clg_id对应的mjr(多个)。grd和cls下拉框项还原到“请选择”状态。
    mjr、grd选项变化时也跟以上同理
--------------------------------------------------
问题: <select name="aa" size="1" onChange="selectMjr(this.value)">
    <option value="1">Computer</option>
    <option value="2"selected>Math </option>
    <option value="3">化学</option>
  </select>  function selectMajor(sltID)
  {
      document.write(sltID);
      <?php
        $clgID = sltID; 这个部分怎么赋值??
        sql="select * from table where id='$clgID'";
        ... ...
      ?>
  }

解决方案 »

  1.   

    有人说这样
    $clgID = "<script>document.write(sltID);</script>";
    可是这样 有语法错误了,因为function本身就在<script>里边。 结果出来
          ); }
     这么个东西了。$clgID = "<script>document.write(sltID);</script>";
      

  2.   

    楼主设计的东西和我的毕业设计部分代码(针对分类和相册的图片上传功能)比较相似
    都是先选第一个下拉列表(选择分类)
    第二个下拉列表会根据选择自动改变内容(再选择相册集)
    然后上传图片至该相册我的实现方法如下客户端使用onchange="location.href='admincp.php?action=settings&operation=upload&type='+this.value;"事件来传递被选择的分类ID
    服务器端收到正确GET方式来传递分类、相册的ID后由服务器端全权处理最终输出下面描述一下我的程序:上传页面的地址是这个
    http://localhost:7626/newdeskroot/admincp.php?action=settings&operation=uploadadmincp.php收到GET参数action=settings后require_once './admin/mod/settings.inc.php';处理后续操作被引入的settings.inc.php收到GET参数operation=upload后require_once './admin./mod/_upload.inc.php'; 调用上传模块以下是部分代码,仅供楼主参考。settings.inc.php
    } elseif($operation=='upload') { //上传壁纸 showtitleandnotice();
    if(!isset($MM_insert)) {
    showformandresult(); //未提交表单的话只显示上传界面
    } elseif ($MM_insert=='form1') {
    $temparr = manageuploadfile(); //若提交表单先处理上传文件
    showformandresult($temparr); //后显示上传界面和处理结果
    }}_upload.inc.php$editFormAction = $PHP_SELF . '?' . cpurl('url');//若存在type请求且type IN desk_type 则按$type返回其包含的相册列表 SQL=SELECT aid, title FROM album WHERE type=XXX;
    if(isset($type) && array_key_exists($type, $desk_type)){
    $query = "SELECT aid, title, totalnum FROM album WHERE type='$type';";
    $aidlistintype = getResult($query);
    }function showformandresult($temparr=NULL) {
    global $type, $aid, $aidlistintype, $desk_type;
    $aidlistcount = $aidlistintype[0];
    $aidlistdata = $aidlistintype[1];
    //将传入的数组还原回$name='value';形式
    if (is_array($temparr)) {
    foreach($temparr as $key => $value) {
    $$key = $value;
    }
    } global $editFormAction, $MM_insert;
    ?><form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
      <table width="0" border="0" class="tb tb2 ">
        <tr class="nobg">
          <td class="td27">分类</td>
          <td class="td27"><label>
            <select name="type" id="type" style="width:250px;" onchange="location.href='admincp.php?action=settings&operation=upload&type='+this.value;">
              <option>请选择分类</option>
    <?php
    if(require_once SITE_ROOT.'./include/desk.type.gbk.php')
    {
    foreach($desk_type as $key => $typevalue)
    {
    ?><option value="<?=$key?>"<?php
    if ( isset($type) && $key==$type ) echo ' selected="selected"';
    ?>><?=$typevalue?></option><?php
    }
    } else {
    die("Desk_Type_Error");
    //ob_flush();
    }
    ?>
            </select>
          </label></td>
        </tr>
        <tr class="nobg">
          <td class="td27">相册</td>
          <td class="td27"><label>
            <select name="aid" id="aid" style="width:250px;" onchange="location.href='admincp.php?action=settings&operation=upload<?php
    if(isset($type) && array_key_exists($type, $desk_type)) echo "&type=$type";
    ?>&aid='+this.value;">
              <option>请选择相册</option>
    <?php
    if($aidlistcount>0){
    foreach($aidlistdata as $key => $value){
    if($value['aid']==$aid){
    echo '<option value="'.$value['aid'].'" selected="selected">'.$value['title'].'</option>';
    }else{
    echo '<option value="'.$value['aid'].'">'.$value['title'].'</option>';
    }
    }
    }
    ?>
            </select></label></td>
        </tr>
        <tr class="nobg">
          <td class="td27">文件</td>
          <td class="td27"><label>
            <input type="file" name="upfile" id="upfile" class="uploadbtn marginbot" style="width:250px;" />
          </label></td>
        </tr>
        <tr class="nobg">
          <td class="td27">标题</td>
          <td class="td27"><span id="sprytextfield1">
            <label>
            <input type="text" name="name" id="name"  class="txt" style="width:250px;"/>
            </label>
          <span class="textfieldRequiredMsg">需要提供一个值。</span></span></td>
        </tr>
      </table>
        <label>
        <input type="submit" name="button" id="button" value="提交" class="btn" />
        </label>
        <label>
        <input type="reset" name="button2" id="button2" value="重置" class="btn" />
        </label>
        <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <script type="text/javascript">
    <!--
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["change"]});
    //-->
    </script>
    <?php if(isset($MM_insert) && $MM_insert=="form1" && $upload_success)
    {
    echo "<br/><font color=red>成功上传</font><br/>文件名: <font color=blue>".$fname."</font><br/>(p)ID:".$lastid."<br/>";
    echo "宽度:".$image_size[0]." 长度:".$image_size[1]; if($imgpreview==1)
    {
    echo "<br>图片预览:<br>";
    echo "<a href=\"".$destination2."\" target='_blank'><img src=\"".$destination2."\" width=".($image_size[0]*$imgpreviewsize)." height=".($image_size[1]*$imgpreviewsize);
    echo " alt=\"图片信息:\r文件名:".$fname."\r上传时间:".date('Y-m-d H:i:s',$temptimestamp)."\" border='0'></a>";
    }
    }
    }
      

  3.   

    这些主要是前端的功夫,跟mysql跟php关系不大实际上最多php提供一个列表数据html就好,或者直接用静态html