4

Is this possible?

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: www.mywebsite.com/ after clicking the submit button, the url to open by javascript is: www.mywebsite.com/print/hello123/

1
  • 2
    Answering your question: yes, it is. Commented Mar 17, 2014 at 10:09

3 Answers 3

7

Check the demo: http://jsfiddle.net/Gv5bq/

HTML:

<input type="text" id="text" />
<input type="button" id="btn" value="Submit" />

jQuery:

$("#btn").click( function() {
    var url = "http://www.mywebsite.com/print/" + $("#text").val();
    window.open(url);
});

UPDATED: (simple JS version) http://jsfiddle.net/Gv5bq/1/

<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);" />
Sign up to request clarification or add additional context in comments.

3 Comments

Who said anything about jQuery?
I believe, this is what i'm looking for! :D as long as it's working. Thank you!
@KareenLagasca alright, I have added the simple JS version as well. :D
1

If you do not want to use jQuery for that here is an approach in pure js.

Define your html-form:

<form action="http://www.mywebsite.com/" method="get" target="_blank" id="my-form">
  <input type="text" name="reference-number" id="reference-number" value="" />
  <input type="submit" value="submit" />
</form>

Define and attach the handler for submission:

<script type="text/javascript">
  var form       = document.querySelector('#my-form'),
      text_field = document.querySelector('#reference-number');

  function submitHandler(){
    // build the new url and open a new window
    var url = form.action + 'print/' + text_field.value;
    window.open(url);

    // prevent form from being submitted because we already 
    // called the request in a new window
    return false;
  }

  // attach custom submit handler
  form.onsubmit = submitHandler;
</script>

Comments

0
<input type="text" value="" id="id"/>
<button type="button" id="go">GO</button>



   $('#go').click(function(){
     var id=$('#id').val();
     var url="http://www.mywebsite.com/hello";
     var new_url=  url+id;
     window.open(new_url);
  });

Fiddle

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.