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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help javascript html

    It's a sort of mad lib. I have written codes for both windows. I just don't know what code to write in, or outside the tellStory function to display the actual story once the other window is called open....

    <html>
    <head>
    <title>Silly Storey About You</title>
    </head>

    <script>
    function tellStorey() {
    setupStoryWindow();
    }

    function setupStoryWindow(name, contentString) {
    var header = "<head><title>" + name
    + " 's story</title><head>"
    + "<h1>" + name + " 's story</h1>";
    var storyWindow = window.open('', 'storyWindow');
    storyWindow.document.write(header);
    storyWindow.document.write(contentString);
    storyWindow.document.close();
    storyWindow.focus();
    }
    </script>

    <body>
    <h1>Tell Your Storey</h1>
    <form name="input"
    method="get">
    <p>Your first name:
    <input type="text" name="yourFirstName" /></p>
    <p>Your gender:
    <select name=yourGenderList>

    <option value="girl">girl
    <option value="guy">guy
    </select></p>
    <p>City you'd like to visit some day:
    <input type="text" name="city"/></p>
    <p>A fruit (plural form):
    <input type="text" name="fruit"/></p>
    <p>Your favorite teacher's name:
    <input type="text" name="teacher" /></p>
    <p>Your best friend's name:
    <input type="text" name="friend" /></p>
    <p>Your favorite actor's name:
    <input type="text" name="actor" /></p>
    <p>A large animal:
    <input type="text" name="animal" /></p>
    <p><input type=button value="Tell a Storey"
    onclick='tellStorey();'</p>
    </form>
    </body>
    </html>


    //here's the story

    "One fine morning on valentine's day a" + yourGenderList + "named" + yourFirstName + "woke up so excited. For today was going to be a single's date night in" + city + ", which is well known for "+ fruit + "." + name + "'s friend" + friend + "recommended that I go because they ended up, curiously
    enough, meeting and marrying my high school teacher" + teacher + ". I'm just hoping to meet someone that looks like" + actor + ". I've had a crush on"+ actor + "for too many years now. Well, realistically, that probably won't happen, but as long as they look like a" + animal + ", then my night will be worth while!"

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,309
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    You have errors in your markup (and story is so spelled, without an e). For example you have not closed your option tags:

    <option value="girl" selected>girl</option>
    <option value="guy">guy</option>

    You cannot refer to the elements in your story just with their HTML element names. You must do something like:-

    Code:
    var contentString = "";
    function tellStorey() {
    var ugl = document.input.yourGenderList.value;
    var yfn = document.input.yourFirstName.value;
    contentString = "One fine morning on Valentine's day a " + ugl + " named " + yfn + " woke up so excited. " 
    alert (contentString);
    I suggest you fix all the errors and get it to output a simple document.write() before going on to writing to the new window.


    An owl in a sack troubles no man.


  •  

    Posting Permissions

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