0

I am learning Javascript.
I want to:

  1. Read a user input (a number that is inserted in to a link address)
  2. Insert the input into a hyperlink string.
  3. Launch the hyperlink.

I am able to read the input and create the string but I cannot get it to launch the website. The string looks correct, however, I am not sure if the problem is actually the string or that I am not launching it correctly. I am able to find examples of each step, but cannot seem to put them together.

Here is my current code: (can't test the link because I cannot see it).
I am sorry if this doesn't come out correctly. It look correct when I paste it.

<script type="text/javascript" >

function myLink() {
    var numberEntered = document.getElementById("lessNum").value; //Read  input
    var lessonlink =  'http://www.ASmarterWayToLearn.com/js/' + numberEntered + '.html'; //Create link

    window.open(lessonLink); //Go to link

    document.getElementById("theLink").value = lessonLink; // check link address

}
</script>

<!-- Read Lesson number -->
<form>
    Lesson Number:<br>
    <input type="text" id="lessNum" onBlur="myLink();"><p>

    <!-- Display link for verification -->
    Link:<br>
    <input type="text" id="theLink" style="width: 400px;"><p>
</form>
    <p>
4
  • 2
    Can you provide us your current code? This may help to understand what you're missing, thanks. Commented Aug 30, 2016 at 12:09
  • Does your url string works? Have you tested it by pasting it in your brother url? Commented Aug 30, 2016 at 12:21
  • Current code (not working). Cannot test string because I cannot see it. Commented Aug 30, 2016 at 16:28
  • <script type="text/javascript" > function myLink() { var numberEntered = document.getElementById("lessNum").value; var lessonlink = 'ASmarterWayToLearn.com/js' + numberEntered + '.html'; window.open(lessonLink); //Go to link document.getElementById("theLink").value = lessonLink; // check link address } </script> <!-- Read Lesson number --> <form> Lesson Number:<br> <input type="text" id="lessNum" onBlur="myLink();"><p> <!-- Display link for verification --> Link:<br> <input type="text" id="theLink" style="width: 400px;"><p> </form> <p> Commented Aug 30, 2016 at 16:30

1 Answer 1

1

In Javascipt :

window.open(yourString);

Source : http://www.w3schools.com/jsref/met_win_open.asp

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

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.