I've been working on a simple JavaScript that makes it possible to switch between different languages in eBay auctions.
As you know eBay does not allow MooTools, so I think this is an Off-Topic.
Here is the source code:
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html dir="ltr" lang="de" xml:lang="de" xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <title>Language Script</title>
- <style type="text/css">
- <!--
- /* General */
- #wrapper {
- margin: 0 auto;
- width: 976px
- }
- #wrapper .de, #wrapper .en {
- display: none;
- visibility: hidden
- }
- #wrapper.german .de, #wrapper.english .en {
- display: block;
- visibility: visible
- }
- -->
- </style>
- <script type="text/javascript">
- <!--
- /* <![CDATA[ */
- function choose(language) {
- var contents = document.getElementById('wrapper');
- var searchbar = document.getElementById('searchbar');
- if (language.options[0].selected) {
- contents.className = 'german';
- searchbar.value = 'Artikel suchen ...';
- searchbar.onfocus = function() {
- if (this.value == 'Artikel suchen ...') this.value = '';
- }
- searchbar.onblur = function() {
- if (this.value == '') this.value = 'Artikel suchen ...';
- }
- } else if (language.options[1].selected) {
- contents.className = 'english';
- searchbar.value = 'Search item ...';
- searchbar.onfocus = function() {
- if (this.value == 'Search item ...') this.value = '';
- }
- searchbar.onblur = function() {
- if (this.value == '') this.value = 'Search item ...';
- }
- }
- }
- /* ]]>
- */
- //-->
- </script>
- </head>
- <body>
- <div id="wrapper" class="german">
- <div id="top">
- <div>
- <p class="de">
- Sprache:
- </p>
- <p class="en">
- Language:
- </p>
- <form method="post" action="">
- <p>
- <select name="language" onchange="choose(this)">
- <option selected="selected">Deutsch</option>
- <option>English</option>
- </select>
- </p>
- </form>
- <hr />
- <form method="get" action="http://shop.ebay.de/merchant/puristi">
- <p>
- <input id="searchbar" name="_nkw" type="text" value="Artikel suchen ..."
- onblur="if (this.value == '') this.value = 'Artikel suchen ...';"
- onfocus="if (this.value == 'Artikel suchen ...') this.value = '';" />
- <input type="submit" />
- </p>
- </form>
- </div>
- </div>
- </div>
- </body>
- </html>
I want to ask you now, whether you find any better ways to change the search-textfield value content language including the onblur and onfocus function. At the moment, there are 2 functions for each language which make the onblur and onfocus effect possible but if I added a third language it would need 2 more functions and so on. I think that would require a lot of code... Maybe too much of code?
- /* <![CDATA[ */
- function choose(language) {
- var contents = document.getElementById('wrapper');
- var searchbar = document.getElementById('searchbar');
- if (language.options[0].selected) {
- contents.className = 'german';
- searchbar.value = 'Artikel suchen ...';
- searchbar.onfocus = function() {
- if (this.value == 'Artikel suchen ...') this.value = '';
- }
- searchbar.onblur = function() {
- if (this.value == '') this.value = 'Artikel suchen ...';
- }
- } else if (language.options[1].selected) {
- contents.className = 'english';
- searchbar.value = 'Search item ...';
- searchbar.onfocus = function() {
- if (this.value == 'Search item ...') this.value = '';
- }
- searchbar.onblur = function() {
- if (this.value == '') this.value = 'Search item ...';
- }
- }
- }
- /* ]]> */
- <input id="searchbar" name="_nkw" type="text" value="Artikel suchen ..."
- onblur="if (this.value == '') this.value = 'Artikel suchen ...';"
- onfocus="if (this.value == 'Artikel suchen ...') this.value = '';" />
Does anyone know how to change the value, onblur and onfocus in a smaller solution as in mine?
Thank you very much!


