SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: onChange issue

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onChange issue

    I have 2 html menu.html and menu2.html,
    and would like to swich one another using "onChange" in each form.

    function pageCh works first time, but it doesn't 2nd time.
    alert("menu2") does not pop up either.




    javascript in menu.html
    HTML Code:
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function pageCh(sectionURL) {
    
    parent.section.location.href = sectionURL;
    if(sectionURL == "section02.xml") {
    parent.menu.location.href = "menu2.html";
    }
    }
    
    //-->
    </script>
    form in menu.html


    HTML Code:
    <form>
    <select onChange="pageCh(this.value)">
    	<option value="section01.xml" selected>1/option>
    	<option value="section02.xml">2</option>
    </select>
    </form>



    javascript in menu2.html

    HTML Code:
    <script language="JavaScript" type="text/JavaScript">
    <!--
    
    alert("menu2");
    
    function pageCh(sectionURL) {
    alert(sectionURL);
    parent.section.location.href = sectionURL;
    if(sectionURL == "section01.xml") {
    parent.menu.location.href = "menu.html";
    
    
    }
    
    //-->
    </script>
    form in menu2.html

    HTML Code:
    <form>
    <select onChange="pageCh(this.value)">
    	<option value="section02.xml" selected>2</option>
    	<option value="section01.xml">1</option>
    </select>
    </form>

    thanks

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,271
    Mentioned
    197 Post(s)
    Tagged
    3 Thread(s)

    bugs

    There are several problems with your code.
    The menu.html form is missing a "<" on the first option's closing tag.
    The pageCh function in menu2.html is undefined. That is, it's missing a closing curly brace - "}".
    I do not know what "parent.section" is referring to, are you sure you shouldn't be using "document" instead?
    The option values are XML files? Not the the HTML test files?
    "Minor" point perhaps, but selected should be selected="selected".


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
  •