Failed to get correct o/p due to wrong in if condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganesh45
    New Member
    • Jun 2012
    • 1

    Failed to get correct o/p due to wrong in if condition

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    	
    	<script type="text/javascript" charset="utf-8" </script>
    	<script type="text/javascript" src="search.js" ></script>
    	<script type="text/javascript" charset="utf-8">
    		
    	function search()
            {
             var x=document.getElementById("From").selectedIndex;
             var y=document.getElementById("From").options;
             var z=y[x].text;
              if(z==Mango)
              {
              document.write('hi');
              }		
            if(z==Apple)
              {
               document.write('hello');
              }
            if(z==Orange)
              {
              document.write(z);
              }
           document.write('haaai');
              }				
    	</script>
    </head>
    	<body bgcolor="#ffccff" >
    	<header>
    	<table>
    		<tr>
    			<td><p style="margin-left: 15px;font-size: 
    
    25px;font-style: inherit;font-family:serif; ">Plan The Journey 
    
    </p></td>
    			
    		
    	</table>
    	  </header>
    	  <fieldset style="margin-top: 50px">
    	  <form name="Fruits">
    	  
    	  	From:<br>
    	  	<select id="From">
            <option value="Apple">Apple</option>
            <option value="Mango">Mango</option>
            <option value="Orange">Orange</option></select><br>
    	  	
    	  	 	 	
    	  	<br><input type="submit" name="SEARCH" value="SEARCH" 
    
    onclick="search()" style="margin-left: 50px"/>
    	 	  </form>
    	  </fieldset>
    	  
    	  </body>
    	  </html>
    Last edited by Dormilich; Jun 11 '12, 09:41 AM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    document.write( ), if used after the page loaded, will cause JS to erase the current document, including all scripts.

    Comment

    Working...