Please help me to acheive this ...

Discussion in 'JavaScript' started by shadow_boi, Dec 19, 2007.

  1. #1
    What I need is: user enters his first name, the first name is appended to the base URL, and when click on GO button, the target URL open in a new window.

    Mockup:

    Please enter your first name: _____ [GO]



    Lets say the base url is http://www.123.com/, the first name that is entered is tom,
    then Go button is clicked, the site: http://www.123.com/tom is opened.

    Thanks.
     
    shadow_boi, Dec 19, 2007 IP
  2. drunnells

    drunnells Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think that this will do what you describe:
    <html>
    <body>
    <script language=JavaScript>
    function openNewWindow() {
            var yourName = document.getElementById('yourName').value;
            var newWindowUrl = 'http://www.123.com/' + yourName;
            if (yourName.length > 0) {
                    window.open(newWindowUrl,'NewWindow','width=600,height=400,resizable=1,location=1,scrollbars=1');
            }
    }
    </script>
    <form>
    Please enter your first name: <input type=text size=10 name='yourName' id='yourName'>
    <input type=button onClick='openNewWindow();' value='Go'>
    </form>
    </body> 
    </html>
    HTML:
     
    drunnells, Dec 19, 2007 IP