我想知道如何通过一个Button在PHP中获得2个动作。 附件是该页面的屏幕截图:
我有以下代码: 对于提交按钮
<form method='POST'>
<div class="form-group">
<input type="text" name="s_amount" style='width:20%;' required>
<input type="submit" class="btn btn-primary" name="submit" value="Submit" />
</div>
</form>
<?php
$s_amount = $_POST['s_amount'];
echo $s_amount;
?>
并点击提交代码按钮
<button id="submitcode"type="button" class="btn btn-default">Submit Code</button>
<pre><code id="output">.../...</code></pre>
当按下Submit代码时,它将执行以下脚本
<script>
$(document).ready(function(){
$("#submitcode").on("click", function(){
ocpu.seturl("https://public.opencpu.org/ocpu/library/base/R")
//arguments
var mysnippet = new ocpu.Snippet("V_CT="+$('[name="CT"]:radio:checked').val()+"\r V_TP="+$('[name="LENGTH"]:radio:checked').val()+$('#input2').val());
//perform the request
var req = ocpu.call("identity", {
"x" : mysnippet
}, function(session){
session.getObject(function(data) {
//data is the object returned by the R function
$("#output").text(data);
});
});
})
});
</script>
我想要的是一个按钮,它不仅可以获取第一个提交按钮(在此处为12,请参阅附件)旁边的值,而且还可以执行脚本。
非常感谢!
答案 0 :(得分:0)
尝试为表单标签提供ID,然后点击Submitcode按钮,使用其ID调用表单。 例如。
<form method='POST'>
function(session){
session.getObject(function(data) {
//data is the object returned by the R function
$("#output").text(data);
// using form id call the form
$("#formdata").submit(); // it will simply submit the form.
});
});
<form method="post" id="formdata"> <!--assign id to form tag-->
</form>
答案 1 :(得分:0)
最终可以使用js非常轻松地做到这一点。
<input type="text" id="VTP" value="0">
并以javascript形式获取值
document.getElementById("VTP").value
@ nikhil borikar:谢谢,但是没有用