Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Unhappy onlick open new window if text input matched that is printed to the page

    New to JavaScript coding, help me write the last part.

    I have everything working accept the last part and I don't know what to do.
    function show() works and shows data entered in text box.
    function open_win() works,but I only need it to open when there is a input
    match say like the name Tom,otherwise I want function show() just to show the input.

    Currently the new window opens every time the button is pressed needs to match input string only before window opens and then string print to window

    I think these two lines are the problems

    (whatever the input) document.getElementById('myDiv').innerHTML = string;

    And var bselect= "Tom" open_win();

    I think I need to set var to the string printed to page to solve the last part.

    lastly, how to I get the blank window to the center of screen,as it covers
    the data in the function show.

    Thanks to all for any help.

    Michael


    Below is my code thus far


    ********************************************************
    <html>
    <head>
    <title>Input</title>
    <script>

    var array = new Array();

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

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

    var bselect= open_win();



    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="Push to see input and open new window"
    onclick="insert(this.form.name.value),show()"/>

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

    *********************************************************

    Dear Philip M , Old Pedant and all who took interest.

    Thank you for your help in trying to resolve my prior post. I have gave up on that approach and it seems that this will give me something that's workable.


    Thanks,very much Mike.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    You don't have ANY PLACE in there where you even TRY to "match" some string.

    So I have no idea
    (a) WHAT string is supposed to trigger the match. Is it ANY element of the array? Is it just the most recently added name? Is it...???
    (b) What that string is supposed to be matched *against*. Always "Tom"??? Or some other string you specify? WHERE do you specify it?
    (c) Why you want to open a *BLANK* window upon those conditions. Always blank. No content at all. Why????

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    At least this code works...as far as it can without those answers.

    Your code was missing HTML tags (especially </td>), had illegal JavaScript, etc.

    Code:
    <html>
    <head>
    <title>Input</title>
    <script>
    
    var array = new Array();
    
    function insertAndShow(val)
    {
        array[array.length]=val;
        show( );
    }
    
    function show() 
    {
        document.getElementById('myDiv').innerHTML = 
            "<b>Name :</b><br>" + array.join("<br/>");
    
        if ( /* what???  under what conditions??? */ false ) 
        {
            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>
        <td width="9"><b>&nbsp;:</b></td>
        <td width="224"><input type="text" name="name"/></td>
    </tr>
    <tr>
        <td colspan=3></td>
    </tr>
    <tr>
        <td colspan=2></td>
        <td width="224">
           <input type="button" Value="Push to see input and open new window"
                  onclick="insertAndShow(this.form.name.value);"/>
        </td>
    </tr>
    </table>
    </form>
    <hr>
    <div id="myDiv"></div>
    </body>
    </html>

  • Users who have thanked Old Pedant for this post:

    mike B (05-08-2009)

  • #4
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Angry Project goal clarification

    Quote Originally Posted by Old Pedant View Post
    You don't have ANY PLACE in there where you even TRY to "match" some string.

    So I have no idea
    (a) WHAT string is supposed to trigger the match. Is it ANY element of the array? Is it just the most recently added name? Is it...???
    (b) What that string is supposed to be matched *against*. Always "Tom"??? Or some other string you specify? WHERE do you specify it?
    (c) Why you want to open a *BLANK* window upon those conditions. Always blank. No content at all. Why????
    *******************************************************

    Quote Originally Posted by Old Pedant View Post
    You don't have ANY PLACE in there where you even TRY to "match" some string.

    So I have no idea
    (a) WHAT string is supposed to trigger the match. Is it ANY element of the array? Is it just the most recently added name? Is it...???
    (b) What that string is supposed to be matched *against*. Always "Tom"??? Or some other string you specify? WHERE do you specify it?
    (c) Why you want to open a *BLANK* window upon those conditions. Always blank. No content at all. Why????
    **************************************************
    Thank you Sir for your time and expertise,forgive me for not being as clear as I should be on my goal. Hopefully with your diligence and help I can put this effort to rest it's given me a real fit of frustration,as I am new to writing code and trying to improve.

    To firm up my needs
    (A) Yes ANY element of the array,but make it so that whatever one element I add the appropriate code (which I don't know how)opens a window or page with a path or location I will get or provide later.

    (b) It should be matched *against* variable stored in the array
    Example was four names(Tom,Bob,ETC) Or some other string specified.
    Again I don't know how?
    (c) Again the window will have content when a match is found, provided It's give it a path,location or specified.

    As for the Why????[/QUOTE] thought I was on the right track quote what was in the array?.

    To put it in a nutshell I need an array of four names and be able to put text input to see if there is a match and if there is give it the abilty to open a new window.

    Lastly in the code I gave last,if you move the blank window you will see the text entered printed to the page(sort of a confirmation on input) but again I don't know how to position the new window upon opening to center it's self.

    Finally the code that I gave the onclick handler launched the window everytime you pressed the button instead of at match only. Again I don't know how to do that either.

    Thanks for patience and help,

    Michael
    Thanks,very much Mike.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Still trying...
    (A) Yes ANY element of the array

    (b) It should be matched *against* variable stored in the array
    Example was four names(Tom,Bob,ETC) Or some other string specified.
    WHICH IS IT???

    You *seem* to be saying that when the user enters a name the he entered before, *then* you want the popup.

    You answer A says "match against any element of the array" and then B says the thing we match *TO* is also an element of the array.

    So if the user enters
    TOM
    BOB
    PAT
    TOM
    *THEN* the second TOM will be ALREADY in the array and so will be found and so will trigger the popup.

    IS THAT WHAT YOU MEAN????

    Or do you mean that you want the array of four names *PREDEFINED*???

    If so, you have to give us the names used to predefine it.

    Or...

    I'm just not sure we are speaking the same language here.

    PLEASE...let's NOT talk about YOUR CODE. It is clearly wrong.

    Let's talk, IN ENGLISH ONLY, about what you want to have happen.

    Don't even use the word "array". Call it a list or something like that. Try to get away from the computerese and just give a description of the actions.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •