...

View Full Version : Simple problem Form options menu trouble..help pls..



Concept
05-07-2008, 08:11 PM
I seem to be having what i am sure is a simple problem. im trying to write a form select menu with multiple options and for each option i want a different response to show up beneath the box. i have been able to produce the text to show up beneath the box with onChange but run into a problem that i dont know how to get the others to give a different response this is what i have tried but to know luck .


<script language="javascript" type="text/javascript">
function do(Value)
{
switch(Value)
{
case "Do This" :

var theNewParagraph = document.createElement('p');
var theBoldBit = document.createElement('b');
var theBR = document.createElement('br');

theNewParagraph.setAttribute('title','Representitives');

var theText1 = document.createTextNode('This is a sample of some ');
var theText2 = document.createTextNode('HTML you might');
var theText3 = document.createTextNode('have');
var theText4 = document.createTextNode('in your document');

theBoldBit.appendChild(theText2);
theBoldBit.appendChild(theBR);
theBoldBit.appendChild(theText3);

theNewParagraph.appendChild(theText1);
theNewParagraph.appendChild(theBoldBit);
theNewParagraph.appendChild(theText4);

document.getElementById('Parent').appendChild(theNewParagraph);

break;

case "Do That" :

var theNewParagraph = document.createElement('p');
var theBoldBit = document.createElement('b');
var theBR = document.createElement('br');

theNewParagraph.setAttribute('title','Representitives');

var theText1 = document.createTextNode('This is a sample of some ');
var theText2 = document.createTextNode('HTML you might');
var theText3 = document.createTextNode('have');
var theText4 = document.createTextNode(' in your document');

theBoldBit.appendChild(theText2);
theBoldBit.appendChild(theBR);
theBoldBit.appendChild(theText3);

theNewParagraph.appendChild(theText1);
theNewParagraph.appendChild(theBoldBit);
theNewParagraph.appendChild(theText4);

document.getElementById('Parent').appendChild(theNewParagraph);

break;
}
}
</script>
</head>

<body>
<form name="testform">
<select name="testselect" id="do" size="1" onchange="do(this.value)">
<option selected="selected"> </option>
<option value="Do This">first option</option>
<option value="Do That">second option</option>
<option value="Do That">third option</option>
</select>
</form>
<p title="Representitives" id="Parent">&nbsp;</p>
</body>

if anyone could tell me what im doing wrong or possibly suggest a different way to achieve this effect it would be greatly appriciated thank you

shyam
05-08-2008, 06:10 PM
do is a keyword in javascript so, you cannot use it as a function name...rename your function and it should work



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum