[英]Radio buttons to new page
嘿,不好意思问这个问题,但是我很困惑,我想让代码在单击单选按钮时转到带有操作的页面,就像stupid.php的愚蠢单选按钮是这样的形式
<form name = "quoted" method="get">
<input id = "poster" type="text" name="poster" required="required" placeholder = "Credited Individual.">
<br>
<textarea class = "actual_quote" name = "actual_quote" required="required" placeholder = "Write the question here!"></textarea>
<br><br><br>
<div class = "checkboxes" required="required">
<h3 style = "margin-top:-20px;">Please select one catagory that the quote falls into.</h3>
<label for="x"><input type="radio" name="x" value="stupid" id = "x" checked="checked" action = "stupid.php" /><span>stupid</span></label>
<br>
<label for="x"><input type="radio" name="x" value="stupider" id = "x" action = "stupider.php" /><span>stupider</span></label>
<br>
<label for="x"><input type="radio" name="x" value="stupidest" id = "x" action = "stupidest.php" /><span>stupidest</span></label>
</div>
<input id = "submit1" type="submit"><br>
</form>
这是每个页面上的php(愚蠢,stupider和stupidest)的php错误,它表示实际报价和发布者未标识索引,对吗?
<div class="wrapper">
<div class="submissions">
<div class="logo-logo"><h2>Question.</h2>
<div class="checkboxes"><?= !empty($_GET['x']) ? $_GET['x'] : '' ?>
</div>
</div>
<div class="top-submit"><?php echo '“' . (!empty($_GET['actual_quote']) ? $_GET['actual_quote'] : '') . '”'; $actual_quote = $_GET['actual_quote'];?>
</div>
<div class="poster"><?php echo "-" . (!empty($_GET['poster']) ? $_GET['poster'] :''); $poster = $_GET['poster'];?>
<div class = "like">
<a href = "javascript:countClicksLike();" class = "btn btn-large" style = "color:green;">Like</a>
<p id = "like" style = "color:green;">0</p>
</div>
<div class = "dislike">
<a href = "javascript:countClicks();" class = "btn btn-large" style = "float:right; color:red;">Dislike</a>
<p id = "dis" style = "color:red;">0</p>
</div>
</div>
<?php
"INSERT INTO submissions(top-submit, poster)
VALUES ($actual_quote, $poster)";
?>
</div>
</div>
抱歉,我已经问了一个小时,但我的想法已经用完了。 任何建议都将受到欢迎。
澄清一下,我希望每个单选按钮在单击“提交”按钮后都进入一个新页面,我希望让它们选中一个单选选项,然后单击“提交”并定向到该页面。 v
<label for="x"><input type="radio" name="x" value="stupid" id = "x" checked="checked" action = "stupid.php" /> <span>stupid</span></label><br>
根据您的单选按钮,
$("input[type=radio]").click(function() {
window.location.href = $(this).attr("action");
});
因此,当用户单击任意一个单选按钮时,单击处理程序会将其带到action
属性中提到的相应页面。
如果仅在选中单选按钮时才希望重定向,而在未选中时不希望重定向,请使用if($(this).is(":checked"))
检查条件
我不明白为什么您不使用anchors
来重定向而不是搞乱输入。 如果使用锚,则不需要任何输入的自定义操作属性。
而且,如果您有一个表单,那么为什么不简单地为此目的使用它的action属性呢? 而且在后端,您可以轻松处理重定向,而不必依赖javascript重定向。
不过,如果您想使用输入进行导航和重定向,并且由于您未提及jQuery,我假定您需要纯Javascript解决方案。 您可以在输入中使用内联javascript,例如:
<label><input type="radio" action="http://www.google.com" onclick="window.location.href=this.action;" />Google</label>
如果您需要jQuery解决方案,请参考mohamedrias上面提供的解决方案。
您是否要根据单选按钮的选择将值发布到不同的php文件中。 如果是的话,我认为您可以使用jquery达到相同的效果。
$("input[type='radio']").click(function(){
$("form").attr('action',$(this).attr('action'));
});
上面的代码会将click事件处理程序添加到所有单选按钮。 当用户单击单选按钮时,单选按钮的action属性将设置为表单。 提交表单后,它将调用当前所选单选按钮的action属性中设置的php文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.