Hi I'm not really sure why this isnt working. Could someone ammend the code so that it is working?

cheers

<html>
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
<title>Limerick Generator</title>

<script type="text/javascript">

  function display(f) 
      {//code to get data from List boxes 
          var DirectionSelect = document.getElementById('Direction') 
          var Direction = DirectionSelect.options[DirectionSelect.selectedIndex].text;

          var VerbSelect = document.getElementById('Verb') 
          var Verb = VerbSelect.options[VerbSelect.selectedIndex].text;

          var DirectionRhymeSelect = document.getElementById('DirectionRhyme') 
          var DirectionRhyme = DirectionRhymeSelect.options[DirectionRhymeSelect.selectedIndex].text;
          for (var i=0; i < document.LimGenerator.bodytype.length; i++)
          {
          if (document.LimGenerator.bodytype[i].checked)
{
var body_val = document.LimGenerator.bodytype[i].value;
} 
 }        
        document.write("There was a " + (body_val) + " " + (f.occupation.value) + " called " + (f.Cname.value) + "<br>" + "Who " + (f.workdone.value) + " more than he wanted to " + (f.Rname1.value) + "<br>" + "One day he " + Verb + " " + Direction + "<br>" + "And said with a " + Expression + "<br>" + "That his " + (f.doing.value) + " was more than a " + (f.Rname2.value) + "<br>");

      }



</script>
<style type="text/css">
 body {
  background-color: moccasin;
  color: #000000;
 }
 :link { color: #0000FF }
 :visited { color: #800080 }
 :active { color: #FF0000 }
 div.c1 {text-align: center}
</style>
</head>
<body>
<div class="c1">
<h2>Limerick Generator</h2>
</div>
<form name="LimGenerator">
<table border="0" width="50%">
<tr>
<td width="25%"><strong>Question</strong></td>
<td width="25%"><strong>Answer</strong></td>
</tr>
<tr>
<td>Name of your character</td>
<td><select name="character" size="1" id="character">
<option>Please Choose</option>
<option>Bill</option>
<option>Will</option>
<option>Jill</option>
<option>Gill</option>
</select><br></td>
</tr>
<tr>
<td>Please choose a body type</td>
<td><select name="body" size="1" id="body">
<option>Please Choose</option>
<option>Thin</option>
<option>Fat</option>
<option>Tall</option>
<option>Short</option>
</select><br></td>
</tr>
<tr>
<td>Two words that rhyme with your character's name</td>
<td><select name="characterrhyme" size="1" id="characterrhyme">
<option>Please Choose</option>
<option>Kill</option>
<option>Spill</option>
<option>Thrill</option>
</select><br></td>
</tr>
<tr>
<td>Name your characters occupation</td>
<td><select name="Occupation" size="1" id="Occupation">
<option>Please Choose</option>
<option>Butcher</option>
<option>Baker</option>
<option>Cleaner</option>
</select><br></td>
</tr>
<tr>
<td>What is the past tense of a task your character might do at work</td>
<td><select name="task" size="1" id="task">
<option>Please Choose</option>
<option>Chopped</option>
<option>Cooked</option>
<option>Cleaned</option>
</select><br></td>
</tr>
<tr>
<td>Pick a past tense verb</td>
<td><select name="Verb" size="1" id="Verb">
<option>Please Choose</option>
<option>Sat</option>
<option>Jumped</option>
<option>Hopped</option>
</select><br></td>
</tr>
<tr>
<td>Pick a direction</td>
<td><select name="Direction" size="1" id="Direction">
<option>Please Choose</option>
<option>Right</option>
<option>Back</option>
</select><br></td>
</tr>
<tr>
<td>Pick a word that rhymes with your direction</td>
<td><select name="DirectionRhyme" size="1" id="DirectionRhyme">
<option>Delight</option>
<option>Contrite</option>
<option>Quack</option>
<option>Clack</option>
</select><br></td>
</tr>
<tr>
<td>Please pick a gender.</td>
<td><input type="radio" name="gender" value="M">male<br>
<input type="radio" name="gender" value="F">female<br></td>
</tr>
<tr>
<td><input type="button" value="submit" onclick="display(this.form)"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><input type="reset" value="Reset" onmouseover="window.status='Clears the form'" onmouseout="window.status='Limerick Generator'"></td>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<h4>Example Limerick Output</h4>
</td>
</tr>
<tr>
<td>
<h4 id="NewLimerick"><em>There was a fat butcher called Bill<br>
Who cooked more than he wanted to kill<br>
One day he sat down<br>
And said with a frown<br>
That his eating was more than a thrill.</em></h4>
</td>
</tr>
</table>
</form>
</body>
</html>

That's a tall order, especially since we don't know what is "not working". Can you elaborate some on what that means?

I've been trying to get it to work for a while now and i'm just really frustrated.

Pretty much I'm trying to get my limerick to output from a group of drop down boxes. I'm fairly sure its working but when i press the submit button to generate the limerick it does nothing.

the problem is there in your element name.there is no element with name "bodytype".Here according to your problem,there must be a checkbox whose name must be "bodytype".

 for (var i=0; i < document.LimGenerator.bodytype.length; i++)//there is no element with name bodytype
          {
          if (document.LimGenerator.bodytype[i].checked)
{
var body_val = document.LimGenerator.bodytype[i].value;
} 
 }        

The best way to check javascript is to place try -catch block in your method,so that you will know where exactly error is.

thanks, ive changed my body type to a checkbox but its still not working :/ any ideas?

there must be a checkbox as

 if (document.LimGenerator.bodytype[i].checked)//this is used for checkbox.

Please check if you have created checkbox

<td>Pick your character body type:</td></tr>
<td><input name="bodytype" type="radio" value="skinny" checked/>skinny</td></tr>
<td><input name="bodytype" type="radio" value="thin" />thin</td></tr>
<td><input name="bodytype" type="radio" value="slender" />slender</td></tr>
<td><input name="bodytype" type="radio" value="chubby" />chubby</td></tr>
<td><input name="bodytype" type="radio" value="fat" />fat</td></tr>

I've got this for my body

hai ChargrO,

small suggestions: (along with above updates of your code)

you got the values of dropdownlist Direction,Verb,DirectionRhyme correctly

you have to do exactly same thing for the remaining drop down boxes

but you are displaying the values of remaining dropbox values directly like

f.occupation.value , f.Cname.value , f.Rname1.value .... etc

please do same as above for the remaining dropdown box values before displaying the values by using document.write()

thats the only thing you have to do for getting the desired result as you wish

please do those modifications in your script code

let me know the status after the modifications as well as if you have any doubts in my clarification

happy coding

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.