Make some text input, print to page and open a new onclick window

I need help:

My page is supposed to take the text of the user input and then show what was entered on the page (without warning) and open a new window on click if a match is found which will be stored in an array or var.


Here is the line I'm having trouble with below:

 onclick="insert(this.form.name.value),show();"/>

      


Here is the code:

          input       

        var array = new Array();

        function insert(val){
            array[array.length]=val;
        }

        function show() {
            var string="<b>All Element of the Array :</b><br>";
            for(i = 0; i < array.length; i++) {
                string =string+array[i]+"<br>";
            }
            if(array.length > 0)
                document.getElementById('myDiv').innerHTML = string;
        }


function open_win(){

window.open ,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, 

copyhistory=no, width=200, height=305")
}

    </script>

</head>

<body>
    <h2>Input</h2>
    <form name="form1">

        <table width="407">
            <tr>
                <td width="154" align="right"><b>Name</b>
                <td width="9"><b>&nbsp;:</b>
                <td width="224">
                <input type="text" name="name"/>
            </tr>
            <tr>

                <td width="154" align="right">
                <td width="9">
                <td width="224">
            </tr>
            <tr>
                <td width="154" align="right">
                <td width="9">
                <td width="224">
                <input type="button" Value="Print Name to page and open new window" 
                       onclick="insert(this.form.name.value),show();"/>

            </tr>
        </table>
    </form>
    <div id="myDiv"></div>
</body>

      

Thank you for your help,

Michael

0


a source to share


2 answers


Try using a semicolon rather than a comma. You want to execute the first function and then the second.

onclick="insert(this.form.name.value); show(); return false;"

      



You add return false;

to prevent the link from executing.

+1


a source


Call subsequent functions from within insert (). Then return true / false to indicate whether the browser should follow the link or not.



0


a source







All Articles