开发者

Javascript Add button after field and get value on click

I have a pre compiled form which i need to insert a button into after a specific field with and ID of addr_postcode can any one show me how to, using javascript,开发者_Python百科 add a button after the field which when clicked takes the value of the field and launches a new window with the value as part of the url. for example:

../DIR/default.aspx?postcode=postcode here

Thanks a nice simple one I hope!

HTML

<TR>
<TD vAlign=top>
<SPAN id=_Captaddr_postcode class=VIEWBOXCAPTION>Post Code:</SPAN>
<BR>
<SPAN id=_Dataaddr_postcode class=VIEWBOX>
<INPUT id=addr_postcode class=EDIT name=addr_postcode maxLength=10 value=test size=15><INPUT name=_HIDDENaddr_postcode type=hidden>
</SPAN>
</TD>
</TR>


Try this:

    function makeButton() {
        var buttonDiv = document.getElementById("addr_postcode");
        var Button = document.createElement("input");
        Button.setAttribute("type", "button");
        Button.setAttribute("id", "ButtonClick");
        Button.setAttribute("value", "New button");
        Button.setAttribute("onclick", "btnClick(" + buttonDiv.value.toString() + ");");
        buttonDiv.appendChild(Button);
    }

    btnClick(URL) {
        window.open(URL,'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜