Hello and welcome to our community! Is this your first visit?
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
    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....

    <title>Silly Storey About You</title>

    function tellStorey() {

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

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

    <option value="girl">girl
    <option value="guy">guy
    <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"

    //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. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,699 Times in 2,675 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:-

    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