Solved

Adding text in textarea onclick event

Posted on 2010-08-19
4
657 Views
Last Modified: 2013-11-24
Hi Experts,

I am looking into somebody else's code here and I am wondering what this line does in javascript func:

 var text = $(id).value;

So far this doesn't work.

	<tr>
				<td class="alignRight" style="font-weight:bold;">General:</td>
				<td>
             <h:inputTextarea id="general-physicalei" value="#{self.formFields.general}" cols="50" rows="8"
              onkeyup="updateCount('#{rich:clientId('general-physicalei')}','modal-physicalexam-form:general-physicalei:notes-count','{CHAR} of 4000 characters remaining',4000);"
              />
              <br/>
              <span id="modal-physicalexam-form:general-physicalei:notes-count" class="hint">Max. 4000 characters remaining</span>
	        	<s:div rendered="true"><script>
              updateCount('#{rich:clientId('general-physicalei')}','modal-physicalexam-form:general-physicalei:notes-count','{CHAR} of 4000 characters remaining',4000);
		</script></s:div>      
		<div id="modal-physicalexam-form:general-physicalei:default">
	              	 <ul>
    <li><a href="#" onclick="addDefault('modal-physicalexam-form:general-physicalei', 'Well developed'); return false;">Add</a> Well developed</li>    
    <li><a href="#" onclick="addDefault('modal-physicalexam-form:general-physicalei',  'Well Nourished'); return false;">Add</a> Well Nourished</li>    	              	 	
	              	</ul>
	            </div>
        </td>
      </tr>

***********************************

function addDefault(id, defaultValue) {

   var text = $(id).value;
   

   if(text == '') {
      text = defaultValue;
   } else if (text.indexOf(defaultValue) == -1){
      text += ((text.charAt(text.length-1) == ' ')?'':' ')+defaultValue;
   }       
  

  $(id).value = text;
   
   //trigger update so we could limit characters
   var eventFunction =  $(id)["onkeyup"];
  
   if(typeof(eventFunction) == "function") {
	 
        eventFunction();
   }
   
}	

Open in new window


thanks,
0
Comment
Question by:dkim18
  • 2
4 Comments
 
LVL 2

Expert Comment

by:ulyssey
ID: 33478005
it s not a javascript function. It s a function made by the owner of the code or from a library like jquery but I don't know from which library this command is from.

to add text in text area you can use this :
document.getElementById("Id").setAttribute("value", "yourtext");
Id: the id of your textarea
0
 
LVL 3

Expert Comment

by:ashley2009
ID: 33478680
The above code, I believe, should not have Java Server Page zone as the above code is java script code and is using either Dojo or MooTools framework or using custom java script library

Please see the below example that talks about different framework:

http://davidwalsh.name/mootools-jquery-dojo


0
 

Author Comment

by:dkim18
ID: 33479789
ulyssey,

I checked generated html and id for the textarea is like this:

<textarea id="j_id5861:j_id3864:modal-physicalexam-form:general-physicalei" name="j_id5861:j_id3864:modal-physicalexam-form:general-physicalei" cols="50" onkeyup="updateCount('j_id5861:j_id3864:modal-physicalexam-form:general-physicalei','modal-physicalexam-form:general-physicalei:notes-count','{CHAR} of 4000 characters remaining',4000);" rows="8"></textarea>

why there is "j_id5861:j_id3864" attached?
0
 
LVL 2

Accepted Solution

by:
ulyssey earned 500 total points
ID: 33481429
I think it s an id generated by the server, the id of the textarea tag is : "j_id5861:j_id3864:modal-physicalexam-form:general-physicalei"

Doesn t matter what is written inside the cote. Everything between the " " represent the id.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tools for analysis of code 4 50
DTD and JAVA versions 1 33
How to escape unsafe HTML tags 4 36
center navbar (navigation menu) on web page 3 23
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question