Results 1 to 3 of 3

Thread: JS problem: script writes "true" to screen

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    28

    JS problem: script writes "true" to screen

    Here is my code:

    Code:
    function menu(dropdown) {
    	var myindex  = dropdown.selectedIndex
    	var SelValue = dropdown.options[myindex].value
    	if (SelValue == "no") {
    		alert("Please select an item to view information")
    
    	} else {
    		var url = "pizza.php?request=menu&mvalue=" + SelValue
    		window.open(url,'mywindow','width=225,height=250 toolbar=no statusbar=no')
    		return true;
    	 }
    
    }
    and the link which I use to call this code:

    Code:
    <a href='javascript:menu(document.menuForm.pizza_options);'>Link</a>
    When I do this, everything goes as expected, except that "true" is written to the base window. Why does this happen and how can I fix it? Thanks

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Re: JS problem: script writes "true" to screen

    Not tested:
    Code:
    <a href="file.htm#" onclick='javascript:menu(document.menuForm.pizza_options);'>Link</a>
    
    <a href="#" onclick='javascript:menu(document.menuForm.pizza_options);'>Link</a>
    
    <a href="" onclick='javascript:menu(document.menuForm.pizza_options);'>Link</a>
    One of them should have the desired effect

  3. #3
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Why put this in an anchor tag? You can put in in the onclick event in a span tag, give it a class that you define in the CSS to look like an anchor link.

    Aside from that, leave out the "return true" line. The function will return on its own, you don't need to explicitly tell it to return and to return a value.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

Posting Permissions

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



Click Here to Expand Forum to Full Width