...

View Full Version : can anyone help me with this - onclick command dont work.



ComoUna
05-31-2005, 06:41 PM
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. :(


<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>

jshl_wiz
05-31-2005, 07:14 PM
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:

<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>

ComoUna
05-31-2005, 07:31 PM
thank for the help. i dont see where i made the mistake though



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum