dongwen7187 2015-01-21 08:22
浏览 60

使用PHP和jQuery在表单之间传递数据:链接选择框

I have 2 inputs forms - Subject and Unit. Units come inside subjects. Example:

  • Subject - English, Math
  • Unit - Nouns, Tenses, Algebra, Geometry

The units table in the DB has a foreign key from the subjects table.

I am making an admin panel which displays me all the content within a subject + unit combination. My options in the subject dropdown are fetched from the DB. For a given value of a subject, I can do the same for the unit dropdown as well.

Passing the data is where I am stuck. I am using the $_GET to take the value from the subject dropdown and passing it on the unit dropdown. The unit dropdown shows the right values but that is removing the value from the subject dropdown.

    $("select.subject").change(function(){
       var selsub = $(".subject option:selected").val();
       var see = $(".subject option:selected").text();
       window.location.href = "index.php?" + "&selsub="+ selsub + "&name=" + see;   
   });

The JS variables get removed because the page is reloading.

I need a quick jquery way in which I can save this value. Not a pro at PHP, haven't worked with AJAX as such, but any ideas will be helpful.

  • 写回答

1条回答 默认 最新

  • douyan5481 2015-01-21 08:29
    关注

    Try this

      $("select.subject").change(function(){
       var selsub = $(".subject option:selected").val();
       var see = $(".subject option:selected").text();
       $.ajax({
         url :"index.php",
         type:"GET",
         data: "selsub="+ selsub + "&name=" + see,
         success:function(response){
           //Do success operation
         }
       }); 
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示