我不能提交我的下拉列表值到我的php页面。
我试着通过javascript制作它,但它不工作。
下面是代码
<div class="col-md-6"><h5>Select your desired shape</h5></div>
<div class="col-md-2">
<input class="span2" id="search_type" name="search_type" type="hidden" >
<div class="btn-group" name="shape" id="shape">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" name="shape">
<span data-bind="label">Shapes</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" name="shape">
<li onclick="$('#search_type').val('sphere'); $('#submitForm').submit()"><a href="#"> Sphere</a></li>
<li><a href="#">Cylinder</a></li>
<li><a href="#">Cube</a></li>
<li><a href="#">Cuboid</a></li>
</ul>
</div>
</div>
</div>`
表单声明是
<form action="submit.php" name="submitForm" id="submit" method="post" role="form" id="submitForm">
我无法解决这个问题。
如果可能的话,给我一些例子的引导形式,其中包括下拉值。'
您的代码正在工作:
<div class="col-md-6"><h5>Select your desired shape</h5></div>
<div class="col-md-2">
<input class="span2" id="search_type" name="search_type" type="hidden" >
<div class="btn-group" name="shape" id="shape">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" name="shape">
<span data-bind="label">Shapes</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" name="shape">
<li onclick="$(alert('it works!')).val('sphere'); $('#submitForm').submit()"><a href="#"> Sphere</a></li>
<li><a href="#">Cylinder</a></li>
<li><a href="#">Cube</a></li>
<li><a href="#">Cuboid</a></li>
</ul>
</div>
</div>
</div>`
在开始使用PHP时要记住的一些事情是,如果你在本地运行,你必须在地址栏中输入地址来启动PHP,你不能仅仅打开index.php文件就期望PHP工作。
但是,你的前端工作。您的PHP已关闭。
可能添加<li onclick input type="submit" method= "post" action="phpfile" name="sphere"><a href="index.php"> Sphere</a></li>
这带来了另一个潜在的问题。前端是否需要Ajax ?现在的方式是,用户将提交并从您的页面重定向到新页面。目标是让他们留在页面上吗?这将需要更多的文件,然后是一个引导索引和一些php.