dongzhuo6137 2017-12-05 08:00
浏览 69

选择后禁用下拉选项(即使是新访客)

I'm working on a website where people can sign up for an event. We've got 8 different teams, based on superhero's. Every team should choose 1 of the 8 superhero's, but non of them should choose the same one.

Is it possible to write some code to disable an option (for every new visitor of the website) after someone has chosen that superhero?

So if 2 people has chosen a superhero, there will only be 6 choices left. These six will be visable, but non-clickable.

So my html form code is (some titles/names are Dutch;)):

<form action="inschrijfformulier.php" method="post" id="cc-m-form-6876142651" target="_blank" class="cc-m-form cc-m-form-layout-1" onsubmit="javascript: setTimeout(function(){location.reload();}, 1000);return true;">
                                                <div class="cc-m-form-loading"></div>

                                                <div class="cc-m-form-view-sortable">
                                                    <div class="cc-m-form-view-element cc-m-form-select" data-action="element" required>
                                                        <label for="ma6b8be54cf86a6410">
    <div>Kies welke held jouw team is!</div>
    </label>
                                                        <div class="cc-m-form-view-input-wrapper">
                                                            <select name="teamnaam" class="cc-m-form-element-input" required>
                                                                <option value="" selected disabled hidden>Selecteer</option>
<option value="Superman">Superman</option>
<option value="Batman">Batman</option>
<option value="X-Men">X-Men</option>
<option value="MegaMindy">Mega Mindy</option>
<option value="Spiderman">Spiderman</option>
<option value="TheHulk">The Hulk</option>
<option value="HitGirl">Hit Girl</option>
<option value="Meerminman">Meerminman</option></select></div></div>
<input type="submit" value="Naar betalen" data-action="formButton">

So if you make a selection and submit the form, it wil link to inschrijfformulie.php, this .php file contains:

<?php 
$name = $_POST['teamnaam'];
$email = $_POST['email'];
$rekeninghouder = $_POST['rekeninghouder'];
$aantalspelers = $_POST['aantalspelers'];
$spelernamen = $_POST['spelernamen'];
$formcontent="Teamnaam: $name 
Email: $email 
Rekeninghouder: $rekeninghouder 
Aantal spelers: $aantalspelers 
Spelers: $spelernamen";
$recipient = "info@sidekickevents.nl";
$subject = "Inschrijfformulier";
$mailheader = "From: $email 
";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: https://www.ticketkantoor.nl/shop/bubbelvoetbal");
 exit;
?>

This makes sure that i'm getting an email with the information they fill in. This works great, I also can see wich superhero they've chosen. Hopefully someone can explain it, because i'm new to php! Thanks in advance!

  • 写回答

3条回答 默认 最新

  • douyin6188 2017-12-05 08:32
    关注

    There is only one way to do it and it is related with server side. First you pick the user's choice:

    Let's assume that your selectbox id is "heroes-combo" and you are using jQuery.

    // this gives you the selected option's value.
    $("#heroes-combo option:selected").attr("value"); 
    

    Now send it to server side via ajax.

    When a user enters the website you need to query your database which heroes are already selected. Lets say the database returns Ironman.

    You then need to mark it as disabled like this:

    $("#heroes-combo option[value='Ironman']").attr("disabled", true)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值