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

    can anyone help me with this - onclick command dont work.

    can anyone please tell me why nothing happens when i click the submit button. i've spent hours on it but cant figure out what i did wrong yet.
    Code:
    <html>
    <body>
    <form = myForm>
    <table border = 5>
    <tr>
    <td>Please enter a name<td>
    <td><input type = text name = txtName></td>
    </tr>
    
    <tr>
    <td>Please enter a country<td>
    <td><input type = text name = txtCountry></td>
    </tr>
    
    <tr>
    <td>Please enter a city<td>
    <td><input type = text name = txtCity></td>
    </tr>
    
    <tr>
    <td>Please enter a color<td>
    <td><input type = text name = txtColor></td>
    </tr>
    
    <tr>
    <td colspan = 4><center><input type = button value = "click to submit" onClick = makeStory()></td>
    </tr>
    </table>
    <textarea name = txtStory rows = 10 cols = 35></textarea>
    </form>
    </body>
    </html>
    <script>
    function = makeStory()
    {
    var person =  document.myForm.txtName.value;
    var country = document.myForm.txtCountry.value;
    var city =    document.myForm.txtCity.value;
    var color =   document.myForm.txtColor.value;
    var story;
    
    story = " one day a man named " + person;
    story += " came to " + country;
    story += "looking for the " + city;
    story += "that was " + color;
    
    story = document.myForm.txtStory.value; 
    }
    </script>

  • #2
    New Coder
    Join Date
    May 2005
    Location
    Alabama
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There were some errors in your code, my advice is always put the names and other properties in quotes (always) and put the functions in the <head> section of the document BEFORE anything else. Now, after some advice here's the fixed code:
    Code:
    <html>
    <head><title></title>
    <script language="JavaScript">
    <!--
    function makeStory(){
    var person = document.myForm.txtName.value;
    var country = document.myForm.txtCountry.value;
    var city = document.myForm.txtCity.value;
    var color = document.myForm.txtColor.value;
    document.myForm.txtStory.value += "one day a man named "+person+" ";
    document.myForm.txtStory.value += "came to "+country+" ";
    document.myForm.txtStory.value += "looking for the "+city+" ";
    document.myForm.txtStory.value += "that was "+color+".";
    }
    //-->
    </script>
    </head>
    <body>
    <form name="myForm">
    <table border="5">
    <tr><td>Please enter a name</td><td><input name="txtName" type="text" /></td></tr>
    <tr><td>Please enter a country</td><td><input name="txtCountry" type="text" /></td></tr>
    <tr><td>Please enter a city</td><td><input name="txtCity" type="text" /></td></tr>
    <tr><td>Please enter a color</td><td><input name="txtColor" type="text" /></td></tr>
    <tr><td colspan="4"><center><input type="button" value="click to submit" onClick = "makeStory()"></td></tr>
    </table>
    <textarea name="txtStory" rows="10" cols="35"></textarea>
    </form>
    </body>
    </html>

  • #3
    New to the CF scene
    Join Date
    May 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank for the help. i dont see where i made the mistake though


  •  

    Posting Permissions

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