weixin_33714884 2018-07-11 17:31 采纳率: 0%
浏览 24

除了提交以外的其他方法

I have a PHP submit form, within that form I have a PHP image gallery that displays images from a folder. (I have a dropdown to select images from different folders).

When I click on an image from the gallery the path to that image is entered into an input field so it can be linked to the other information when submitted.

My problem is when I choose a different image gallery folder from the dropdown it submits the form. I understand why it does this, but am unsure how to change the way it uses PHP to choose different folders to JS/JQ so there is no need for a submit or refresh.

Here is the relevant code...

<script>
function change(){
    document.getElementById("myfolders").submit();
}
</script>


$subF = $_POST['otherFolders'];

<form id="myfolders" method="post">

  <select name="otherFolders" onchange="change()">
        <option selected="selected">Other Galleries</option>
        <?php
        $otherFolders = $dirs2;
        foreach($otherFolders as $item){
        ?>
        <option value="<?php echo $item; ?>"><?php echo $item; ?></option>
        <?php
        }
        ?>
    </select>

Thanks for any help

  • 写回答

1条回答 默认 最新

  • weixin_33726313 2018-07-11 18:03
    关注

    I believe that you dont want to refresh the page when a user clicks on submit. There is very limited info from the question, so I cannot provide changes to your code. But, what you want to do is either prevent the form from submitting by using the preventDefault(); function in JS and then reading the form elements, submitting an aJax request to your server (PHP), and using the server response to display on the page.

    If you do not want the form to even submit, you can just make a button that does not submit a form, but simply has an onClick event that reads the form elements and does the same as above.

    Form submit will always refresh the page if not prevented. If an action attribute is not provided, it will default to submitting the form to the current page.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)