开发者

Radio button onclick insert value to href

I’m trying to insert the url from an onlick event in the the radio buttonsto the href link but it not working. Here’s I have so far.

<input type="radio" name="orderID" value="1"  onclick="javascript:document.getElementById('editBTN').href='forms/editForm.cfm?orderID ='&this.value">

<input type="radio" name=" orderID " value="2" onclick="javascript:document.getElementById('editBTN').href='forms/editForm.cfm?orderID ='&this.value">

Etc…

The link below href should change depending on which radio button is clicked.

<a href="" id="editBTN"> Edit Order</a>

The above script returns the current url wi开发者_运维百科th “localhost/myApp/0” at the end. If I remove this ('forms/editForm.cfm?orderID='&) from the radio button it correctly return the orderId.

I would like this result localhost/myApp/forms/editForm.cfm?orderID=1. Any suggestion would be greatly appreciated.


JavaScript uses + to concatenate strings, not &:

onclick="document.getElementById('editBTN').href=
         'forms/editForm.cfm?orderID ='+this.value"

(line break added for readability) should work.

You can lose the javascript: prefix, by the way.


You listed jquery as one of your question tags. I'd simply place the following script onto my page and attach the click event on the radio's to push their value into the appropriate button attribute.

$('input[name=orderID]').click(function(e) {

$('#editBTN').attr('href', 'forms/editForm.cfm?orderID ='+$(this).val());

});


I think the & before this.value should be a +

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜