2014-04-02 55 views
0

I got the below code:如何通過國家ID到<a href> tag?

<form method="post" accept-charset="UTF-8" action="showPartners.action?" id="_form" onsubmit="return selCheck();"> 
<div style="float: left; width: 350px;"> 
    <span class="text_vert"> Select Country : </span>&nbsp;&nbsp; 
    <s:select style="width:200px;" onchange="loadBusinessList();" 
    headerKey="-1" headerValue="Country Select" list="couList" 
    listKey="idCountry" listValue="label" id="countryId" 
    name="countryId"> 
    </s:select> 
</div> 

<a href='addPartner.action?height=550&width=850&id=<s:property value="countryId"/>'" >Insert</a> 
</form> 

What I need to do is to pass the country ID to the link in the a href tag, but what I get is the ID=0.

I would appreciate any help.

回答

0

Try to assign the country id in a separate variable while changing the value in the select list and then pass that variable in the href link.

1

The easiest solution would be to use JavaScript, like so:

<s:select style="width:200px;" onchange="loadBusinessList();document.getElementById('anchor_id').href=document.getElementById('anchor_id').href.replace(/&id=(?:$|\d+)/, '&id=' + this.value)" ... 

And:

<a id="anchor_id" href='addPartner.action?height=550&width=850&id=0'" >Insert</a> 

Please note: the code assumes your countryIds are integers.

+0

謝謝你的回覆。 您的解決方案會生成一個鏈接:「http:// localhost:8080/admin/addPartner.action?height = 550&width = 850148」。 「id =」丟失。一旦我選擇了國家並想改變選擇,該ID就不會第二次更新。任何消化? – TheKolanN

1

Best way it's to create a curl and use it.

<c:url value="addPartner.action" var="myAddPartnerUrl" scope="page"> 
<c:param name="height" value="550" /> 
<c:param name="width" value="850" /> 
<c:param name="id" value="${countryId}" /> 
</c:url> 

html:

<a href="${myAddPartnerUrl}"> 

you can manage dinamically your url and no problem about syntax since c:url create the right string itself. More, you can use param for "addPartner.action" instead to put directly in c:url (same for rest of params).

Link Tutorial

+0

此解決方案不起作用。調試器sais:「pageContext.getExpressionEvaluator()。evaluate(」$ {myAddPartnerUrl}「,java.lang.String.class,((javax.servlet.jsp.PageContext)pageContext).getVariableResolver(),null)=>沒有類「org.apache.jasper.el.E​​xpressionEvaluatorImpl」中的「評估」方法接受類型爲「(java.lang.String,java.lang.Class,org.apache.jasper.el.VariableResolverImpl,java.lang.String」對象)「。」<「 – TheKolanN

+0

嘗試導入<%@ taglib uri =」http://java.sun.com/jsp/jstl/core「prefix =」c「%> – MrPk

+0

這會給出」未終止的<%@ taglib標記「 – TheKolanN