Loading ...
Sorry, an error occurred while loading the content.

_Javascript simple problem

Expand Messages
  • lystemic
    Seems a simple enough problem, one that most websites do, but I m having a problem: When a button is clicked on the home page (index.html) I want: A) another
    Message 1 of 3 , May 8, 2010
    • 0 Attachment
      Seems a simple enough problem, one that most websites do, but I'm having a
      problem:

      When a button is clicked on the home page (index.html) I want:
      A) another page to come up and
      B) display the correct information (based on the button clicked).

      To do so I'm passing an argument containing the name of the button to a
      javascript function that should:
      a) Bring up the new page
      AND, BASED ON WHAT IS PASSED TO IT WILL:
      b) Cause the correct information to be displayed in the frame by activating the
      routine: MM_setTextOfLayer('TrailingSubText','','<iframe
      align="top" frameborder="1" height="422"
      width="644" src="website programming.htm"
      >\n</iframe>')

      What happens is that:
      - the function is accessed
      - The following alerts show up:
      - "0" [in response to alert("This is the " & buttonName); ]
      - "This is after a."
      - "This is the b" [in response to alert("This is the b"); ]
      - "This is after b."


      QUESTIONS:
      - Why is the code in both if statements being activated (when only one should
      respond)?
      - Why isn't the MM_setTextOfLayer... routine being activated?
      - How can the problem be solved?

      HERE ARE THE SPECIFICS:


      ATTACHED TO THE BUTTON ON PAGE index.html IS THE FOLLOWING

      onclick= "javascript:updatePage('a')


      THIS IS THE INFORMATION IN THE JAVASCRIPT FUNCTION

      var buttonName = "c"; //declared variable passed in function updatePage as
      string


      function updatePage(buttonName){
      if (buttonName = "a") {
      document.location.href = 'SearchAndRescue.html';
      alert("This is the " & buttonName);
      MM_setTextOfLayer('TrailingSubText','','<iframe align="top"
      frameborder="1" height="422" width="644"
      src="website programming.htm" >\n</iframe>')
      }
      alert("This is after a.");

      if (buttonName = "b") {
      document.location.href = 'SearchAndRescue.html';
      alert("This is the b.");
      MM_setTextOfLayer('TrailingSubText','','<iframe align="top"
      frameborder="1" height="422" width="644"
      src="website programming.htm" >\n</iframe>')
      }
      alert("This is after b.");

      }
    • David Smart
      Check all your IF statements ... if (buttonName = a ) should be if (buttonName == a ) (i.e. two equal signs, not 1). Regards, Dave S ... From: lystemic
      Message 2 of 3 , May 18, 2010
      • 0 Attachment
        Check all your IF statements ...

        if (buttonName = "a")

        should be

        if (buttonName == "a")

        (i.e. two equal signs, not 1).

        Regards, Dave S

        ----- Original Message -----
        From: "lystemic" <jar1@...>
        To: <JavaScript_Official@yahoogroups.com>
        Sent: Sunday, May 09, 2010 4:19 AM
        Subject: [JavaScript] _Javascript simple problem


        > Seems a simple enough problem, one that most websites do, but I'm having a
        > problem:
        >
        > When a button is clicked on the home page (index.html) I want:
        > A) another page to come up and
        > B) display the correct information (based on the button clicked).
        >
        > To do so I'm passing an argument containing the name of the button to a
        > javascript function that should:
        > a) Bring up the new page
        > AND, BASED ON WHAT IS PASSED TO IT WILL:
        > b) Cause the correct information to be displayed in the frame by
        > activating the
        > routine: MM_setTextOfLayer('TrailingSubText','','<iframe
        > align="top" frameborder="1" height="422"
        > width="644" src="website programming.htm"
        > >\n</iframe>')
        >
        > What happens is that:
        > - the function is accessed
        > - The following alerts show up:
        > - "0" [in response to alert("This is the " & buttonName); ]
        > - "This is after a."
        > - "This is the b" [in response to alert("This is the b"); ]
        > - "This is after b."
        >
        >
        > QUESTIONS:
        > - Why is the code in both if statements being activated (when only one
        > should
        > respond)?
        > - Why isn't the MM_setTextOfLayer... routine being activated?
        > - How can the problem be solved?
        >
        > HERE ARE THE SPECIFICS:
        >
        >
        > ATTACHED TO THE BUTTON ON PAGE index.html IS THE FOLLOWING
        >
        > onclick= "javascript:updatePage('a')
        >
        >
        > THIS IS THE INFORMATION IN THE JAVASCRIPT FUNCTION
        >
        > var buttonName = "c"; //declared variable passed in function updatePage as
        > string
        >
        >
        > function updatePage(buttonName){
        > if (buttonName = "a") {
        > document.location.href = 'SearchAndRescue.html';
        > alert("This is the " & buttonName);
        > MM_setTextOfLayer('TrailingSubText','','<iframe align="top"
        > frameborder="1" height="422" width="644"
        > src="website programming.htm" >\n</iframe>')
        > }
        > alert("This is after a.");
        >
        > if (buttonName = "b") {
        > document.location.href = 'SearchAndRescue.html';
        > alert("This is the b.");
        > MM_setTextOfLayer('TrailingSubText','','<iframe align="top"
        > frameborder="1" height="422" width="644"
        > src="website programming.htm" >\n</iframe>')
        > }
        > alert("This is after b.");
        >
        > }
        >
        >
        >
        >
        > ------------------------------------
        >
        > Visit http://aiaiai.com for more groups to joinYahoo! Groups Links
        >
        >
        >


        --------------------------------------------------------------------------------



        No virus found in this incoming message.
        Checked by AVG - www.avg.com
        Version: 8.5.437 / Virus Database: 271.1.1/2881 - Release Date: 05/18/10
        06:26:00
      • lystemic
        Thanks The conditionals now work. And the function updatePage(buttonName)works IF what you re trying to do is change information on the SAME PAGE. This page is
        Message 3 of 3 , May 24, 2010
        • 0 Attachment
          Thanks

          The conditionals now work.

          And the function updatePage(buttonName)works IF what you're trying to do is change information on the SAME PAGE. This page is the "second page"-- the page called by the Home Page.

          Now for the real problem:

          The Home page cotains a (splash screen) graphic followed by the same menu buttons. I want to be able to click on one of those buttons and:

          1) Change the url to the "second page"
          2) Have the same menu come up (properly highlighted to reflect the selection)
          3) Enable the same changes that the function UpdatePage(buttonName) implemented.

          So I wrote a function changePage(buttonName) that based on which conditional it passes:
          1) Changes the url (to a page that looks very much like the page you came from except that the menu in question is moved up the page)
          2) Calls the function updatePage(buttonName) which is supposed to make the same changes to this "second page" that it made to the same page when activated from that page.

          It doesn't work. The url changes, but UpdatePage is never called and none of the alerts after UpdatePage() appear.

          Can a JavaScript function CHANGE A URL AND MAKE CHANGES TO THE NEW PAGE (based on the argument passed)?

          Here's the new function:

          function changePage(buttonName){
          if (buttonName == "a") {
          alert("Passed a ");
          document.location.href = 'SearchAndRescue.html';
          alert("Passed a...changedPage ");
          UpdatePage('a');
          alert("Passed a...changedPage...UpdatePage ");
          }

          if (buttonName == "b") {
          alert("Passed b");
          document.location.href = 'SearchAndRescue.html';
          alert("Passed b...changedPage ");
          UpdatePage('b');
          alert("Passed b...changedPage...UpdatePage ");
          }
          }







          > >
          > > THIS IS THE INFORMATION IN THE JAVASCRIPT FUNCTION
          > >
          > > var buttonName = "c"; //declared variable passed in function updatePage as
          > > string
          > >
          > >
          > > function updatePage(buttonName){
          > > if (buttonName = "a") {
          > > document.location.href = 'SearchAndRescue.html';
          > > alert("This is the " & buttonName);
          > > MM_setTextOfLayer('TrailingSubText','','<iframe align="top"
          > > frameborder="1" height="422" width="644"
          > > src="website programming.htm" >\n</iframe>')
          > > }
          > > alert("This is after a.");
          > >
          > > if (buttonName = "b") {
          > > document.location.href = 'SearchAndRescue.html';
          > > alert("This is the b.");
          > > MM_setTextOfLayer('TrailingSubText','','<iframe align="top"
          > > frameborder="1" height="422" width="644"
          > > src="website programming.htm" >\n</iframe>')
          > > }
          > > alert("This is after b.");
          > >
          > > }
          > >
          > >
          > >
          > >
          > > ------------------------------------
          > >
          > > Visit http://aiaiai.com for more groups to joinYahoo! Groups Links
          > >
          > >
          > >
          >
          >
          > --------------------------------------------------------------------------------
          >
          >
          >
          > No virus found in this incoming message.
          > Checked by AVG - www.avg.com
          > Version: 8.5.437 / Virus Database: 271.1.1/2881 - Release Date: 05/18/10
          > 06:26:00
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.