#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    2
    Rep Power
    0

    JavaScript SELECT box problem


    Hi y'all

    Can anyone figure out a problem with this? It's probably stupidly simple but I can't spot it.

    Look at http://www.webmastersdog.com/jsproblem.html - you can see that the script is meant to display a message on the right-hand side of the page, depending on what is chosen from the drop-down box on the left. BUT the script won't let you select anything other than the very last item (in IE6). Why?

    Here's the code:


    Code:
    <textarea name="add" style="float:right;background-color:white;color:black;font-family:Arial,Helvetica,Monaco;size:normal;border:0px;width:350px;overflow:visible">
    </textarea>
    <form method="post" action="" name="listpanes">
    	<select name="comID" onChange="changeDescription()">
    		<option value="">+select+</option>
    		<option value="">msg one</option>
    		<option value="">msg two</option>
    	</select>
    </form>
    
    <SCRIPT LANGUAGE="JavaScript" type="text/javascript">
    
    function changeDescription() {
    	if(document.listpanes.comID.selectedIndex="1") {	
    	add.value='Message ONE';
    	add.disabled=1;
    	}
    	if(document.listpanes.comID.selectedIndex="2") {	
    	add.value='Message TWO';
    	add.disabled=1;
    	}
    }
    
    </script>
    Last edited by Jefferrs; February 6th, 2002 at 01:55 PM.
  2. #2
  3. T-Shirt Tragic
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    886
    Rep Power
    321
    most of your html code was missing from the document, the textarea element was outside the form tags and you were trying to reference a form element without first referencing the form object ...
    try this-
    Code:
    <html>
    <head>
    <title></title>
    <script LANGUAGE="JavaScript" type="text/javascript">
    
    function changeDescription() {
        
        if (document.listpanes.comID.selectedIndex > 0)
            document.listpanes.add.value=document.listpanes.comID.value;
    
    }
    </script>
    </head>
    <body>
    
    
    
    <form method="post" action="" name="listpanes">
    
    <select name="comID" onChange="changeDescription()">
    <option value="">+select+</option>
    <option value="Message ONE">msg one</option>
    <option value="Message TWO">msg two</option>
    </select>
    
    <textarea name="add"></textarea>
    </form>
    </body>
    </html>
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    2
    Rep Power
    0
    Thank you

IMN logo majestic logo threadwatch logo seochat tools logo