0

For a HTML button element i want to bind the below onclick event

<a class="btn btn-sm btn-bitbucket" id="test" onclick="document.location.href='https://192.22.32.101/V0_3_4/cgi-bin/config.cgi'">

The above one works fine and the cgi got executed perfect . But the requirement is i want to replace "https://192.22.32.101/V0_3_4/cgi-bin/config.cgi" with a varible since this is dynamic . Can someone provide the java script. Like the below.

HTML

<a class="btn btn-sm btn-bitbucket" id="test"> .

JAVA SCRIPT

document.getElementById("test").onclick = "document.location.href="HOST_CGI_PATH""; (I am facing difficulties defining the correct quotes)

I am doing this binding in document ready function.Here the HOST_CGI_PATH is a javascript variable refers to the actual path.

Thanks

2 Answers 2

1

Do

document.getElementById("test").onclick = function(){ 
     document.location.href=HOST_CGI_PATH;
});
Sign up to request clarification or add additional context in comments.

Comments

0

You're overcomplicating it:

document.getElementById("test").href = HOST_CGI_PATH;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.