Grab the RSS feed

Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Hide/Show button and change textarea as readonly

Hi friends,
Most of the webdevelopers faceing the situation like this.Some times we need to make the text area as editable one when they are going to click the button.We can easily make it by using the javascript.Here I am explaining with the check box.When the user going to click the check box its going to be readonl.Because first it is the editable one.You can make it also in reverse.
For that you put readonly as true in HTML and change the readonly as false in javascript.


< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > 
< html xmlns="http://www.w3.org/1999/xhtml" > 
< head > 
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" / > 
< title > Untitled Document< /title > 
< /head > 

< body > 
< script type="text/javascript" > 

function blah(bool) {
if(bool) {
document.getElementById("ta").readOnly = true;
document.getElementById('tst').style.visibility = 'visible'
}
else {
document.getElementById("ta").readOnly = false;
}
}

< /script > 

< textarea id="ta"  > < /textarea > 
< input type="checkbox" onclick="blah(this.checked)" / > 
< div id="tst" style="visibility:hidden" > < input type="button" value="save"/ > < /div > 
< /body > 
< /html > 



Leave the comments to improve us....

How to get the textarea ID using javascript

Most of the programmers using the comment
element = document.getElementById(id); to get the value or something from the HTML pages.Some times the ID may be changed because of some reasons.At that time we need to get the ID of the HTML element using Javascript and make our coding successfull.
Here I list the coding to get textarea id .


var divEls = document.getElementsByTagName("textarea");
var i = 0;
for(i=0;i<divEls.length;i++)
alert(divEls[i].id);

You can also using this type to get the Id of div.For that simply put the div instead of textarea.

Leave the comments to improve us...

Text area with bold,Italic,etc..


We are all know about Emails.In that we have seen the text area with the options to make our content bold,italic,etc.We can also make the text area like that in our site.
For that what we have to do?
There are lots of plugins available on the internet.I am using the plugin TinyMCEIn that we have almost all of the options to make the text area as richable and user friendly.

How to integrate Tiny MCE to your site?
You can simply
download from the above site and then you can integerate the javascript from tiny mce.

Depending upon your needs there are lots of themes(simple,advanced) are available.

What are the problems I am facing during usage?

During the integeration there are n problems.I simply integerate the script.But when I am going to use I face a small problem.That is my site is fully developed using the ajax concepts.When I am using the editor the first time mail was sent successfully.During the mail send I validate through javascript.When I send the mail at second time it wont be sent.Why?
I got the result of the textarea Id is changed.So when I am validate at second time the error displayed there is no such an ID.Why it was changed?Because the tiny MCE change the text area Id depending upon that use.

How I solved the problem?
I analyzed the Id going to be mce_0,mce_1,etc.So I simply get the id using Javascript (You can read this post for get the ID using javscript )and pass that id during validation.Now the problem is solved simply.

Please give the comments to improve us.....

Set maxLength Using Javascript

Hello friends,

Sometimes we need to set the maxlength for textbox or textarea depend upon the value selected.
For example if you select the country then we need to set the zip code length depend upon the country.
If the country selection is depend upon the ajax it is easy to set the length.

For example in US the zip code contain only 5 characters.But in india this going to be six.
It is simple and easiest way in the javascript.Set the maximum length by using the following code...

  
document.getelementid('textbox1").maxLength=10

Click Here to download as PDF format..

Leave the comment to improve us...

Declare the variable globally in Java script

Today I am facing the problem of get the value from the variable that declared inside the function. But I need to get that value from outside of the function.

For that we need th declare the variable globally is the best way of doing program.

In Java script it is simple technique to globally declare the variable.

How can you declare the variable globally?

Is we need to put global infront of that.No…

See the following program…..

Function1()

{

Var myname;//declared globally

Function2()

{

Var myaddress;//with in the function

Myname//access in this function

}

Function3()

{

Myname;

}

}

When accessing the global variable don’t put var within the function…

Read and use it.Leave the comments for improvements…

 
Real Time Web Analytics