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

    Question Simple problem Form options menu trouble..help pls..

    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 .
    Code:
    <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

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    do is a keyword in javascript so, you cannot use it as a function name...rename your function and it should work
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

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