selectbox show input filed

Discussion in 'JavaScript' started by roice, Oct 31, 2010.

  1. #1
    Hello,

    I have this code:
    <script> 
    	function checkForOther(obj) 
    	{ 
    		if (!document.layers) 
    		{ 
    			var txt = document.getElementById("otherTitle"); 
    			if (obj.value == "new") 
    			{ 
    				txt.style.display = "inline"; 
    				// gives the text field the name of the drop-down, for easy processing 
    				txt.name = "selTitle"; 
    				obj.name = ""; 
    			} 
    			else 
    			{ 
    				txt.style.display = "none"; 
    				txt.name = ""; 
    				obj.name = "selTitle"; 
    			} 
    		} 
    	} 
    </script> 
    PHP:
    it's should hide/show input field accourding the user choice - if he choose "<option value='new'>new</option>", the follow action should happend:

    				<li id='otherTitle'>
    					<label for='new'>new artist</label>
    					<input type='text'  name='new_artist_name' />				
    				</li>
    PHP:
    The script works, but when I click "submit" the parameter that the "select box" should send don't get send...

    here is the full code:
    
    				<li>
    					<label for='artist'>Artists</label>
    					<select name='artist_id' onchange=\"checkForOther(this)\">
    						<option value='new'>new artist</option>";
    						$query = mysql_query("SELECT id, name FROM `chords_artists` ORDER BY `name` ");
    						while($index = mysql_fetch_array($query)) 
    						{	
    							$artist_id = $index['id'];
    							$artist = $index['name'];
    							echo "<option value='$artist_id'>$artist</option>";
    						}
    						
    					echo "	
    					</select>
    				</li>	
    				
    				<li id='otherTitle'>
    					<label for='new'>new artist:</label>
    					<input type='text'  name='new_artist_name' />				
    				</li>
    
    
    PHP:
    Can you please help me with it?
     
    roice, Oct 31, 2010 IP