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


Groups > comp.lang.javascript > #7820

Re: Changing letters in boxes

From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: Changing letters in boxes
Date 2011-10-30 15:08 +0200
Organization A noiseless patient Spider
Message-ID <j8ji7m$fj8$1@dont-email.me> (permalink)
References <1cb16076-87c8-4bc6-8007-1efddfb7530b@s10g2000yqa.googlegroups.com>

Show all headers | View raw


30.10.2011 14:26, fulio pen wrote:

> I wanted to accomplish something, and know javascript or jquery can do
> the work, but my knowledge on both languages is too limited.

You don't need jQuery for a simple job like this. Using jQuery may 
simplify coding a lot, but here probably the only thing it would be 
useful for is simplifying the reference to a specific element. And 
jQuery isn't really a language (at least not in the same sense as 
JavaScript is a programming language) but a library that you may use in 
addition to JavaScript, to ease coding.

> My idea is in the following web page.
>
> http://www.pinyinology.com/js_learning/letters.html

Remove the jQuery-related script elements (the reference to the library 
doesn't work anyway) and add the following:

<script>
function letters(a,b,c) {
   document.getElementById('box').innerHTML =
     '<td>' + a + '</td><td>' + b + '</td><td>' + c +  '</td>' ;
  }
</script>

Change the <tr> tag for the table to <tr id=box>. (Here and before "box" 
is just an identifier; choose another one if you can find a more 
self-documenting name.)

Add onclick attributes to the <input> element to make them as follows:

box #1: <input type="text" value='x y z' size='10' 
onclick="letters('x','y','z')" /><br />
box #2: <input type="text" value='a b c' size='10' 
onclick="letters('a','b','c')" /><br />
box #3: <input type="text" size='10' onclick="letters('','','')" />

This way, the entire <tr> element is changed at the same time as 
requested (though in practice, just replacing the <td> contents in 
sequence would be just as good, unless there is a real risk of 
intervening interrupts).

Note that clicking on the last box makes the letters disappear entirely, 
i.e. the contents of each <td> element becomes empty, and this affects 
the layout - the cells shrink. (They are still 10px wide and high due to 
the padding you set.) If this is not desirable, there are varyings 
things you can do, depending on the exact desired appearance. For 
example, you could use '\xa0' (standing for no-break space) instead of 
'' to make the cells preserve height (though not width) when cleared.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

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


Thread

Changing letters in boxes fulio pen <fuliopen@yahoo.com> - 2011-10-30 05:26 -0700
  Re: Changing letters in boxes "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-10-30 15:08 +0200
    Re: Changing letters in boxes fulio pen <fuliopen@yahoo.com> - 2011-10-30 07:14 -0700
    Re: Changing letters in boxes fulio pen <fuliopen@yahoo.com> - 2011-10-30 10:22 -0700
      Re: Changing letters in boxes "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-10-30 20:14 +0200
        Re: Changing letters in boxes fulio pen <fuliopen@yahoo.com> - 2011-10-30 12:27 -0700
    Re: Changing letters in boxes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-30 18:58 +0100
      Re: Changing letters in boxes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-30 19:07 +0100
      Re: Changing letters in boxes Andrew Poulos <ap_prog@hotmail.com> - 2011-10-31 06:15 +1100
        Re: Changing letters in boxes Lasse Reichstein Nielsen <lrn.unread@gmail.com> - 2011-11-01 17:17 +0100
          Re: Changing letters in boxes Andrew Poulos <ap_prog@hotmail.com> - 2011-11-02 07:10 +1100
            Re: Changing letters in boxes Andreas Bergmaier <andber93@web.de> - 2011-11-01 23:37 +0100
              Re: Changing letters in boxes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-02 00:20 +0100
        Re: Changing letters in boxes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-01 18:01 +0100
      Re: Changing letters in boxes Matt McDonald <matt@fortybelow.ca> - 2011-10-30 17:42 -0600
        Re: Changing letters in boxes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-31 02:19 +0100
          Re: Changing letters in boxes Matt McDonald <matt@fortybelow.ca> - 2011-10-31 21:29 -0600
            Re: Changing letters in boxes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-01 11:52 +0100
      Re: Changing letters in boxes RobG <rgqld@iinet.net.au> - 2011-10-30 19:33 -0700
        Re: Changing letters in boxes "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-10-31 08:37 +0200
        Re: Changing letters in boxes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-31 11:50 +0100
  Re: Changing letters in boxes faqir <faqir@faqir.com> - 2011-11-03 23:20 +0200

csiph-web