使用<a> tag or other way

时间:2015-10-31 09:41:09

标签: javascript servlets

I have this modal which sets the orderID to a modal. In this modal, it has a <form></form> that does another request and an <a> tag that does another request. My problem is that, the value is coming from a JavaScript function and I cannot use <a href="ApproveSurgery?orderid15=<%=orderID%>"></a> So, how do I pass the value to the Servlet? Or is there other easier way? I tried doing this

Html:

<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal15" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="LabRequest2" method="POST"> //Form that is doing other request
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">
                        <a name="doctororder15" id="doctororder15" style="color: white;"></a>
                    </h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" name="orderid15" id="orderid15">
                    <input type="hidden" name="remarks15" id="remarks15">
                    // this is the a tag that is doing another request aside from the form
                    Continue/Approve Surgery? <a href="ApproveSurgery?orderid151515">Yes</a>
                </div>
                <div class="modal-footer">
                    <button data-dismiss="modal" class="btn btn-default" type="button">Back</button>
                    <button class="btn btn-theme" type="submit">Send Request</button>
                </div>
            </form>
        </div>
    </div>
</div>

JavaScript:

        function setOrder15(orderID) {
            for(var i = 0; i < orderids.length; i++) {
                if(parseInt(orderids[i]) === orderID) {
                    $(".modal-body #orderid15").val(orderids[i]);
                    document.getElementsByName("orderid151515")[0].innerHTML = orderids[i];
                }
            }
        }

1 个答案:

答案 0 :(得分:4)

你的想法应该有效。但是你没有为<a>元素命名,所以它可能不会按原样运行。另外,你必须更换整个HTML。

您还可以使用javascript函数设置globalOrderId全局变量,然后使用javascript转到新页面:

<a onclick="goToNewPage()">Yes</a>

并且:

function goToNewPage() {
    window.location = 'ApproveSurgery?orderid15=' + globalOrderId;
}