SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2005
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript onClick problem

    I'm just trying to show someone a demo and wanted to show how a user can select a country from a list and when clicked on the javascript would produce the information in the id#country section.

    I am sure the javascript is 100% right however it doesn't seem to work. Any ideas?

    Code is below


    HTML Code:
    <form action="#" enctype="multipart/form-data" method="post">
    			
    			<select>
    			
    				
    				<option value="Greece">Greece</option>
    				<option value="India" onclick="changeCountry">India</option>
    				<option value="Nigeria">Nigeria</option>
    				<option value="Pakistan">Pakistan</option>
    				<option value="Saudi Arabia">Saudi Arabia</option>
    				
    				<option value="Spain">Spain</option>
    				
    				<option value="Sri Lanka">Sri Lanka</option>
    				
    				<option value="USA">USA</option>
    				<option value="USA Mobile">USA Mobile</option>
    				
    				<option value="Zimbabwe">Zimbabwe</option>
    
    			
    			
    			</select>
    			
    			</form>
    			<br />
    			<span id="country">
    		
    			</span>

    Code:
    <script type="text/javascript">
    function changeCountry(){
    	var newHTML = '<p class="red-highlight">IRAQ is available 5p</p>
    			<br />
    			<p>Dial 0844 550 0011 + your international number</p>
    			<br />
    			<p class="black-highlight">Use the drop down list to find your access number.
    			Dial the access number.  E.G. USA 0844 835 0011
    			At the prompt, dial your full international number.                  E.G. 001 212 555 1234			</p>';
    			
    	document.getElementById('country').innerHTML = newHTML;
    }
    </script>

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    A string can't span multiple lines. Put the newHTML on a single line.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think instead of using click event on the option element, you can use change event on the select element and check your matched option value.


Bookmarks

Posting Permissions

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