-1

I have input box and a submit button.

  1. The user will input their "reference number" (example: "hello123")
  2. user will click the submit button.
  3. after clicking the submit button, the javascript will open url link in a New browser Tab with a url link (which i assigned) plus the input of the user (which is hello123)

Assigned url is (for example): www.mywebsite.com/ after clicking the submit button, the url to open by javascript is: www.mywebsite.com/print/hello123/

i have this code:

<input type="text" id="text" />
<input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value);" />

but it's really not working. any ideas what's wrong?

3 Answers 3

2

We form the new URL as follows:

var url = "www.mywebsite.com/"+document.getElementById('text').value;

In the onclick event, change it to :

window.location=url;

Sign up to request clarification or add additional context in comments.

Comments

1

Using jQuery is the simplest way to do this

$("#btn").click(function() {
    window.location="www.yourwebsite.com/url/here/"+$("#text").val();
})

Comments

0

Just replace window.open with window.location.

Also if you are already on www.mywebsite.com just write

window.location.href=document.getElementById('text').value.

1 Comment

it is an external website. will try your approach.

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.