Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Mike Stramba

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Condensed "Send html Select Value to Textarea"

//
// When the <select> is changed it should send the current select.value
// to a given texarea (id='content' in this case)

// The user can also just type directly into the textarea, the idea being that
// the <select> gives access to a stored list of words. Actually the practical
// use I'm trying to make of it is to hook it into the 'Instiki' R.O.R. wiki

//
// With FireFox 2.0.04, this is working UNTIL something is manually typed into
// the text area, then it stops working.
//

// It DOES work with IE6.

//
// It doesn't work with Opera 9.0.2
//

function SendSelectValueToTextArea(selectValue,targetTextArea)
{
   var txtNode=document.createTextNode(selectValue);
   var textArea=document.getElementById(targetTextArea);
   textArea.appendChild(txtNode);
}

 <select  onchange="SendSelectValueToTextArea(this.value,'content')" >

JavaScript Fill Textarea from HTML Select not working with FireFox or Opera but does in IE6

//
// Fill textarea with keywords from HTML Select element
//

This code DOES work in I.E6 (on my machine (XP pro), but doesn't work in Firefox 2.0.0.4 or Opera 9.0.2

The idea is to be able to either type in the text area directly or choose from a list of saved words in the select box. When a new choice is made from the select, it automatically gets inserted into the text area.

With Firefox , when the page is first loaded, I can choose from the select control and it works until I type something in the text area, and then it stops working.

With Opera 9.02, the select control doesn't work at all.

IE6, works fine.

Any hints tips, appreciated, as I'm a novice with javascript / DOM programming.

I quite possibly am not using the most correct / efficient document.XXX calls here.


Mike

You can test it at http://mstramba.com/fb5.html

///////////////
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <style type="text/css">textarea {  height:200px; width:50%;}</style>

<script type="text/javascript">

function htmlData(selectValue,targetTextArea)
{
//   alert("select box changed to : '" + selectValue + "'");

   var txtNode=document.createTextNode(selectValue);
   var textArea=document.getElementById(targetTextArea);
   textArea.appendChild(txtNode);
}
</script>
</head>

<body>
 <form method="post">
 <select name="country" id="selbox" onchange="htmlData(this.value,'content')" />
   <option value="#">-Select-</option>
   <option value="SuperCaliFragilisticExpiAliDocius">SuperCaliFragilisticExpiAliDocius</option>
   <option value="Discombombulatively">Discombombulatively</option>
   <option value="I don't understand how this can be happening">I don't understand how this can be happening</option>
 </select>

 <textarea name="content" id="content">Type some text or choose words from the select control</textarea>

 <input type="submit" />
</form>
</body>
</html>

Ruby - "meta method" execute

//
//
// attempt to execute a method indirectly, I don't know if
// it's possible, but I suspect it is, and probably just
// have the syntax wrong
//

ar = %w(apples bananas oranges)

print "\n ar.class = #{ar.class}"

print "\n ar.methods = #{ar.methods.sort}"
puts "======================================================="

mets = ar.methods.sort

#
# this doesn't work ... is there a syntax for doing this?
#                       i.e. calling a 'meta' method ?
#
# call each method of 'ar' (an array)
#
#

mets.each {|method| ar.method} 

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS