Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30669

Re: Failing to get DIV content to flip between initial and alternate version

Newsgroups comp.lang.javascript
Subject Re: Failing to get DIV content to flip between initial and alternate version
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <nk04oi$t3m$1@dont-email.me>
Date 2016-06-17 11:32 +0200
Message-ID <XnsA62A755FDFCC0eejj99@194.109.6.166> (permalink)

Show all headers | View raw


$Bill <news@todbe.com> wrote on 17 Jun 2016 in comp.lang.javascript:

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>    "http://www.w3.org/TR/html4/loose.dtd">

<!DOCTYPE HTML> will do in the 21 century.

> <HTML>
> <HEAD>
> <TITLE>Flip Test</TITLE>
> </HEAD>
> 
> <BODY>
> 
> <SCRIPT>               // init global vars
> 
> var isGrid = 0;               // cause a switch between grid text & list
> text // isGrid == 0 means init, == 1 means grid active, == 2 means list
> active var gridTxt = "<P>Grid Text</P>";          // just some test text
> var listTxt = "<P>List Text</P>";          // just some test text
> document.body.onload = init;               // init to grid text

window.onload = init;

then you can set the <script> inside the <head>, where it belongs.

> 
>      // function to swap grid and list content
> function FlipType () {
> 
> // alert ("0: isGrid=" + isGrid);               // debug
> // get the current div object by id
> var flipDiv = document.getElementById("FlipDiv");
> // 1st execution on init doesn't get to here (init:, 0:)
> // alert ("1: " + flipDiv.innerHTML);          // debug
> if (isGrid != 1) {                    // set to grid if not grid
>      flipDiv.innerHTML = gridTxt;
>      // alert ("2: " + flipDiv.innerHTML);     // debug
>      isGrid = 1;                    // set flip switch to grid
>} else {                         // else set to list
>      flipDiv.innerHTML = listTxt;
>      // alert ("3: " + flipDiv.innerHTML);     // debug
>      isGrid = 2;                    // set flip switch to list
>}
> // alert ("4: isGrid=" + isGrid);               // debug
> // button click execution gets to here, but seems to re-call init like
> the page // is re-loading ???
> // 0:, 1:, 2: 4:, init:. 0:
> 
>}
>      // init calls FlipType to set initial grid text
> function init () {
> document.body.onload = null;          // trying to prevent 2nd load

This is nonsense, a document always loads once, and then is a new document.


> alert ("init: isGrid=" + isGrid);     // getting called on button
> click-wrong // if (isGrid == 1 || isGrid == 2) { ; } else { FlipType ();
> } this fails to work FlipType ();                    // to set the text
> the first time to grid 
>}
> 
> </SCRIPT>
> 
> <!-- button to test FlipType -->
> <FORM>
>    <!-- for some reason FlipType is executed twice when I click it ???
>    maybe the body is re-loading from onload ??? -->
>    <BUTTON onclick="FlipType()">Flip View</BUTTON>

The form is executed, so the page reloads and the javascript execution is 
lost, so do a "return false" to prevent the form from executing:

<button onclick='flipType();return false;'>Flip View</button>

or set the <button> outside a <form>


> </FORM>
> 
> <!-- actual code to flip goes inside this form in the DIV -->
> <FORM>
> <FORM METHOD="POST"
> ACTION="http://www.todbe.com/cgi-bin/prt_tv_sched.pl"> 
>    <BR><INPUT TYPE="HIDDEN" NAME="DATE" VALUE="20160612">
>    <DIV ID="FlipDiv"><P>Replace Me</P></DIV>
>    <BR><INPUT TYPE="SUBMIT" VALUE="Print Selected Schedule">
> </FORM>
> 
> </BODY>
> </HTML>

I prefer lowercase html, less screaming.

And leave out the copious commenting on usenet, 
as the lines get too long.

Try this:

============================================
<!DOCTYPE HTML>
<html>
<head>
<title>Flip Test</title>
<script>
   var isGrid = 0;         
   var gridTxt = '<p>Grid Text</p>';      
   var listTxt = '<p>List Text</p>';      
   function flipType() {
      var flipDiv = document.getElementById('FlipDiv');
      if (isGrid != 1) {            
         flipDiv.innerHTML = gridTxt;
         isGrid = 1;            
      } else {               
         flipDiv.innerHTML = listTxt;
         isGrid = 2;            
      };
   };
      
   function init() {
      // document.body.onload = null;      
      // alert ('init: isGrid=' + isGrid);   
      flipType();            
   };
   window.onload = init;         
</script>
</head>

<body>
<form>
   <button onclick='flipType();return false;'>Flip View</button>
</form>
<form>
<form method='post' action=''
   <br><input type='hidden' name='date' value='20160612'>
   <div id='FlipDiv'><p>Replace Me</p></div>
   <br><input type='submit' value='Print Selected Schedule'>
</form>
</body>
</html>
===================================

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Failing to get DIV content to flip between initial and alternate version $Bill <news@todbe.com> - 2016-06-16 23:18 -0700
  Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-17 11:32 +0200
    Re: Failing to get DIV content to flip between initial and alternate version $Bill <news@todbe.com> - 2016-06-17 19:00 -0700
      Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-18 11:35 +0200
        Re: Failing to get DIV content to flip between initial and alternate version $Bill <news@todbe.com> - 2016-06-18 19:16 -0700
          Re: Failing to get DIV content to flip between initial and alternate version Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-06-19 14:23 +0000
            Re: Failing to get DIV content to flip between initial and alternate version $Bill <news@todbe.com> - 2016-06-20 04:13 -0700
              Re: Failing to get DIV content to flip between initial and alternate version $Bill <news@todbe.com> - 2016-06-20 04:16 -0700
                Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-26 12:53 +0200
                Re: Failing to get DIV content to flip between initial and alternate version $Bill <news@todbe.com> - 2016-06-26 16:22 -0700
                Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-27 10:49 +0200
                Re: Failing to get DIV content to flip between initial and alternate version Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-06-27 13:58 +0000
                Re: Failing to get DIV content to flip between initial and alternate version Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-27 05:43 +0200
                Re: Failing to get DIV content to flip between initial and alternate version John Harris <niam@jghnorth.org.uk.invalid> - 2016-06-27 09:38 +0100
                Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-27 11:00 +0200
                Re: Failing to get DIV content to flip between initial and alternate version John Harris <niam@jghnorth.org.uk.invalid> - 2016-06-28 10:04 +0100
                Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-28 12:13 +0200
                Re: Failing to get DIV content to flip between initial and alternate version John Harris <niam@jghnorth.org.uk.invalid> - 2016-06-29 16:16 +0100
                Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-29 19:48 +0200
          Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-25 16:40 +0200
    Re: Failing to get DIV content to flip between initial and alternate version "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-18 10:59 -0700
      Re: Failing to get DIV content to flip between initial and alternate version Stanimir Stamenkov <s7an10@netscape.net> - 2016-06-18 22:32 +0300
        Re: Failing to get DIV content to flip between initial and alternate version "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-18 13:50 -0700
          Re: Failing to get DIV content to flip between initial and alternate version Stanimir Stamenkov <s7an10@netscape.net> - 2016-06-19 09:40 +0300
            Re: Failing to get DIV content to flip between initial and alternate version "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-19 12:21 -0700
            Re: Failing to get DIV content to flip between initial and alternate version Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-25 18:37 +0200
    Re: Failing to get DIV content to flip between initial and alternate version Stanimir Stamenkov <s7an10@netscape.net> - 2016-06-18 22:17 +0300
      Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-25 16:45 +0200
        Re: Failing to get DIV content to flip between initial and alternate version "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-25 17:17 +0200
          Re: Failing to get DIV content to flip between initial and alternate version "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-25 19:02 +0200

csiph-web