设置下拉错误消息

时间:2016-08-30 22:08:25

标签: jquery html css

是否可以为下拉菜单设置错误消息?

在第一页上,我有一个下拉菜单,用户可以选择任意组合,然后点击提交。

在第二页上,我有相同的精确下拉菜单,如果用户没有选择相同的组合,则会显示一些错误。



<select id="men" class="select_class1" name="subselector" style="display:none" >
    <option value="">Choose an item</option> 
    <option value="tsm">T-Shirt</option>
    <option value="lsm">long sleeve</option>
    <option value="tankm">Tank Top</option>
</select>  
<select id="color" class="select_class1" name="subselector" style="display:none" >
    <option value="">Choose an item</option> 
    <option value="blue">blue</option>
    <option value="red">red</option>
    <option value="black">black</option>
</select>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

是。您可以通过 PHP JQUERY

的组合来实现这一目标

让我们说这是你的第一页

secondPage.php

然后这将是您的<?php $subselector = $_POST['subselector']; ?> <form action="anotherPage.php" method="post"> <select id="men" class="select_class1" name="subselector"> <option value="">Choose an Item</option> <option value="tsm">T-Shirt</option> <option value="lsm">Long Sleeve</option> <option value="tankm">Tank Top</option> </select> <input type="submit" value="submit" /> </form> <!-- Now using jQuery to prevent the form from submitting if only the previous selected value doesn't correspond with the present selected value --> <!-- don't forget to include your jQuery library here --> <script> $('form').submit(function(e){ prevSelVal = "<?php echo $subselector; ?>"; presentVal = $('select').val(); if(prevSelVal !== presentVal){ e.preventDefault(); alert('Your Previous Selected Value must Correspond With Your Present Selected Value'); } }); </script>

var c = document.getElementById('test'), ctx = c.getContext('2d');
ctx.save();
ctx.fillStyle = "rgba(0,0,255,0.5)";
ctx.beginPath();
ctx.moveTo(25, 0);
ctx.lineTo(50, 50);
ctx.lineTo(0, 50);
ctx.lineTo(25, 0);
ctx.fill();
ctx.fillStyle = "rgba(255,0,0,0.5)";
ctx.beginPath();
ctx.moveTo(50, 0);
ctx.lineTo(75, 50);
ctx.lineTo(25, 50);
ctx.lineTo(50, 0);
ctx.clip();
ctx.clearRect(0, 0, 100, 100);
ctx.fill();
ctx.restore();