Showing posts with label JAVASCRIPT. Show all posts
Showing posts with label JAVASCRIPT. Show all posts

Monday, December 30, 2013

Javascript validation for dynamic element



Many time in web-application we come across the functionality to build - adding dynamic form elements and validating them. its pretty simple with .rules() and validate()


 var newElement = $('<input type="text" name="input' + count + '" value="" />');
            $('form').append(newElement);
            newElement.rules('add', {
                required: true,
                messages: {
                    required: 'This field is required'
                }
            });

and add this script and jQuery, using foreach() to retrieve the data being $_POST'ed:

<script type="text/javascript">
   $(document).ready(function() {
        var numberIncr = 1; // used to increment the name for the inputs

        function addInput() {
            $('#inputs').append($('<input class="comment" name="name'+numberIncr+'" />'));
            numberIncr++;
        }

        $('form.commentForm').on('submit', function(event) {

            // adding rules for inputs with class 'comment'
            $('input.comment').each(function() {
                $(this).rules("add", 
                    {
                        required: true
                    })
            });            

            // prevent default submit action         
            event.preventDefault();

            // test if form is valid 
            if($('form.commentForm').validate().form()) {
                console.log("validates");
            } else {
                console.log("does not validate");
            }
        })

        // set handler for addInput button click
        $("#addInput").on('click', addInput);

        // initialize the validator
        $('form.commentForm').validate();

   });


</script>



Know more about JAVASCRIPT, JQUERY, Form Validation, Validate
Hope you have enjoyed the post let us know your views.


Friday, April 19, 2013

5 ways to redirect URL with Javascript




5 ways to redirect URL with Javascript



some days before i was searching for a trick to force redirection of a page to java script event . how can we Redirect to an HTTP POST Request with Javascript? 

I summarized 5 ways to redirect URL(The purpose of below script is to perform a local redirect using Javascript).


way 1
 



way 2
 




way 3
 




way 4
 


way 5   
 




 







Hope you have enjoyed to read this post,
let me know if you have more suitable suggestions.




you might be more interested in JQUERY, JAVASCRIPT, TIPS AND TRICS.
want to know more about the author ?





Good Day [/ Night] ! Happy Google + ing !

Wednesday, April 3, 2013

How to Add Maxlength On TextArea Using JQuery

How to Add Maxlength On TextArea Using JQuery

How to Add Maxlength On TextArea Using JQuery


here is the pretty good and easy to understood code for making textarea working with maxlength property.


JQuery Code :
 

 
    $(document).ready( function () {
 
	maxLength = $("textarea#comment").attr("maxlength");
        $("textarea#comment").after("
" + maxLength + " remaining
"); $("textarea#comment").bind("keyup change", function(){checkMaxLength(this.id, maxLength); } ) }); function checkMaxLength(textareaID, maxLength){ currentLengthInTextarea = $("#"+textareaID).val().length; $(remainingLengthTempId).text(parseInt(maxLength) - parseInt(currentLengthInTextarea)); if (currentLengthInTextarea > (maxLength)) { // Trim the field current length over the maxlength. $("textarea#comment").val($("textarea#comment").val().slice(0, maxLength)); $(remainingLengthTempId).text(0); } }

HTML Code :
 
<body>

<h1>TextArea maxlength with jQuery</h1>

<textarea id="comment" maxlength="10" rows="10" cols="60" ></textarea>

</body>

Working Demo



Any more Questions ? let me know with comments.
for projects write me at bhavinrana07@gmail.com



Friday, November 2, 2012

JQuery UI Datepicker - End Date should not be less than Start Date

JQuery UI Datepicker - End Date should not be less than Start Date


i have the simplest and shortest way to implement validations in start date and end date.i have used familiar names in this example better to be understood. 

Check out the Working Demo. 


if you are developer then i dont think i have to write more lines for understanding.


Hope you have enjoyed the post ! any more ideas / questions about the same ? let me know by comments !

Know More About :
PHP Freelancing India

Monday, October 15, 2012

JQuery set to tackle mobile Web development

The JavaScript-based tools for Web development are widely used for desktop and laptop browsers. JQuery Mobile will let coders reach mobile phones, too. read Main Article.
Countless developers use jQuery software tools today to build advanced Web sites  and to ease the difficulties of spanning multiple browsers. 


Cheers !
Hope you got the Ans !
still having probs ? let me know by comments !

Know More About :
PHP Freelancing India

Saturday, September 8, 2012

How can I check if one string contains another substring in JavaScript? JavaScript: string contains

Q. How can I check if one string contains another substring in JavaScript?








Usually I would expect a String.contains() method, but there doesn't seem to be one.

My code is:

var allLinks = content.document.getElementsByTagName("a");

for (var i=0, il=allLinks.length; i<il; i++) {
   
   elm = allLinks[i];
   var test = elm.getAttribute("class");
   if (test.indexof("title") !=-1) {
   alert(elm);
   foundLinks++;

}
}

if (foundLinks === 0) {
   alert("No title class found");
}
else {
   alert("Found " + foundLinks + " title class");
}



Solution :



var s = "foo";
alert(s.indexOf("oo") != -1);

indexOf returns the position of the string in the other string. If not found, it will return -1.





Cheers !
Hope you got the Ans !
still having probs ? let me know by comments !

Know More About :
PHP Freelancing India


Friday, September 7, 2012

Monday, September 3, 2012

How do I check a checkbox with jQuery or JavaScript?


How do I check a checkbox with jQuery or JavaScript?

 
jQuery 1.6+


: Solution : 

Use the new .prop() function:
$(".myCheckbox").prop("checked", true);
$(".myCheckbox").prop("checked", false);


jQuery 1.5 and below

The .prop() function is not available, so you need to use .attr().

To check the checkbox (by setting the value of the checked attribute) do $('.myCheckbox').attr('checked','checked')



and for un-checking (by removing the attribute entirely) do $('.myCheckbox').removeAttr('checked')


Any version of jQuery : 

If you're working with just one element, it will always be fastest to use DOMElement.checked = true. The benefit to using the .prop() and .attr() functions is that they will operate on all matched elements.


if (this.checked) 
// Assuming an event handler on a checkbox




:D
Steel facing probs ? let me know by comments !

Know More About :
PHP Freelancing India


Saturday, September 1, 2012

How to format a JSON date?

How to format a JSON date? Problems with Json Date ?


jsonDate :
         /Date(1224043200000)/



Solution : 
var date = new Date(parseInt(jsonDate.substr(6)));


 
The substr function takes out the "\/Date(" part, and the parseInt function gets the integer and ignores the ")\/" at the end. The resulting number is passed into the Date constructor.

Cheers !
Hope you got the Ans !
still having probs ? let me know by comments !

Know More About :
PHP Freelancing India



Check checkbox checked property using jQuery

Check checkbox checked property using jQuery,  check the checkbox checked with JQuery


Solution :

if ($('#isAgeSelected').is(':checked')) {
$("#txtAge").show();
} else {
$("#txtAge").hide();
}

You can shorten this using ternary, some might say it's a bit less readable, but that's how I would do it:$('#isAgeSelected').is(':checked') ? $("#txtAge").show() : $("#txtAge").hide();


here's a much prettier way to do this, using  
toggle:

$('#isAgeSelected').click(function () {
$("#txtAge").toggle(this.checked);
});
<input type="checkbox" id="isAgeSelected"/>
<div id="txtAge" style="display:none">Age is something</div>​


Cheers !
Hope you got the Ans !
still having probs ? let me know by comments !

Know More About :
PHP Freelancing India


Friday, August 31, 2012

Get query string values in JavaScript

Is there a plugin-less way of retrieving query string values via jQuery (or without)?

If so, how, and if not what plugin do you recommend?
You don't need jQuery for that purpose you can use the pure JavaScript: 


function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}


Cheers ! 
Hope you got the Ans ! 
still having probs ? let me know by comments ! 



Know More About :

Thursday, August 30, 2012

Testing if something is hidden with jQuery, Check Form Element is hidden



Testing if something is hidden with jQuery, Check Form Element is hidden



In jQuery, suppose you have an element of some kind that you're hiding and showing, using .hide(),.show() or .toggle(). How do you test to see if that element is currently hidden or visible on the screen?


$(element).is(":visible") 




Hope you got the Ans !
still having probs ? let me know by comments !




Know More About :
PHP Freelancing India 

Tuesday, August 28, 2012

How to get select radiobutton value using its name in jQuery? Getting the value of a selected radio button out of a radio group in jQuery.

How to get select radiobutton value using its name in jQuery? 

Getting the value of a selected radio button out of a radio group in jQuery.



Just want to point out that Jeff's answer might suit others because it can be used to get the value from anywhere, not just within a click handler for the radio button. here is preety simple solution. 

$('input:radio[name=theme]:checked').val();



:D 
Steel facing probs ? let me know by comments ! 




Know More About :
PHP Freelancing India 


Saturday, September 24, 2011

Submit Form Using Ajax (Post)


Hi Googler,
here is some code , will be helpfull in submit form using ajax post.
you need to create following files. 


Post.html





<script type="text/javascript" language="javascript">// <![CDATA[
var h_request = false;
function makePOSTRequest(url, parameters) {
h_request = false;

<!--more-->

if (window.XMLHttpRequest) //MOZILLA
{
h_request = new XMLHttpRequest();
if (h_request.overrideMimeType)
{
h_request.overrideMimeType('text/html');
}
}
else if (window.ActiveXObject) { // IE
try {
h_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
h_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!h_request) {
alert('Cannot create XMLHTTP instance');
return false;
}

h_request.onreadystatechange = alertContents;
h_request.open('POST', url, true);
h_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
h_request.setRequestHeader("Content-length", parameters.length);
h_request.setRequestHeader("Connection", "close");
h_request.send(parameters);
}

function alertContents() {
if (h_request.readyState == 4) {
if (h_request.status == 200) {
result = h_request.responseText;
document.getElementById('myspan').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
}

function get(obj) {
var poststr = "mytextarea1=" + encodeURI( document.getElementById("mytextarea1").value ) +
"&mytextarea2=" + encodeURI( document.getElementById("mytextarea2").value );
makePOSTRequest('post.php', poststr);
}

// ]]></script>

<form action="javascript:get(document.getElementById('form1'));" name="form1" id="form1">
<textarea id="mytextarea1">testing data
1
2
3
</textarea>
<textarea id="mytextarea2">testing data 2
4
5
6</textarea>
<br>
<input type="button" name="button" value="Submit"
onclick="javascript:get(this.parentNode);">

</form>

<br><br>
Server-Response:<br>
<hr>
<span name="myspan" id="myspan"></span>
<hr>
Post.php
<?
print_r($_POST);
?>


Hope post helped you.
for questions comment on this.


:D

Know More About :
PHP Freelancing India

Wednesday, September 21, 2011

Hire PHPBB Developer for Robust Web Forum Development











Hi Googler,

In the online business, businessmen suppose to be using various web techniques to promote the business on the web. The more interaction with the related entities can open the more avenues for the business and one of the best modes of interaction and sharing information on the web is forums.Internet forums with business websites can do amazing business promotional work. 

Developing web forum involves a fair programming work that is complex for novice businessmen. One of the popular & unique PHPBB (PHP Bulletin Board) systems for developing robust internet forums to business websites is available in the web development. PHPBB software is based on PHP programming language. However, web forums can be developed using various other computer programming languages such as Perl, Java and ASP. Internet forum development for websites is complex and costly process. Businessman can hire PHPBB developer / programmer for making it cost-effective & customize to use with business website.


Internet forums are efficient tool to use with business as they incredibly great source to reach and converse with people. Designing, developing and hosting of internet forums is costly process and small businessman or online business company suppose to seek affordable alternative. As PHP is an open source scripting language and hire dedicated PHPBB developer is the best option that can save precious money. He can specially build or perform PHPBB development, customize it and host cost – effectively. 

Anyone in the online business can hire PHPBB Developer from PHP Web Development Company. The concept of hiring dedicated developer is popular in the present times, which is very helpful in technical terms as well as in the matter of affordability. Customized designing, development and hosting all three can be derived from one professional. Moreover, a hired PHPBB Developer can provide the benefits or implement the features of all updated versions such as PHPBB2 & PHPBB3 into business.
any questions ? let me know by comments ..
:D
Know more About :
PHP Freelancing India

Tuesday, September 20, 2011

Speed up Page Load by reducing HTTP requests with PHP


Hi Googler,


A nice technique to speed up your page loading times is to try to reduce the amount of calls your browsers has to make to the server. This will be every image, every css and every JavaScript file included in the webpage. Each time you want to load in one of these elements you will be sending a request to the server which will return the requested object known as a HTTP request.

Reduce Page Loading Time With PHP

Each one of these uses up time on your page loading, so to reduce page load all you have to do is reduce the amount of calls being made. But what if you want to organise you JavaScript files, jquery file, general file, application file and page file. There could be upto 4 requests for some javascript for the page.
It is possible in PHP to combine these JavaScript files together and trick the browser into thinking they are just one JavaScript file, therefore reducing the amount of calls being made to the server. This is done by reading the JavaScript with PHP then changing the header to JavaScript like the example below.
Create a PHP file and use the readfile function to bring in your Javascript files then change the header to Javascript and the server will treat this page as Javascript.


readfile(jquery.js');
readfile(general.js');
readfile(jquery-ui.js');
readfile(page.js');
header('Content-type: text/javascript');

The above technique can also be used with CSS files or a combination of them both.

hope this post helped,
any questions ? let me know by comments ..
:D 

Monday, September 19, 2011

All you need to know about web site heatmaps overview

Hi Googler,
Site heatmaps are graphical illustrations of data where variables represent values of data which are recorded in two-dimensional tables. The origin of the heatmaps is the 2D displays, and its values are represented in a data matrix. In most instances, values that are larger are represented by small squares that are either dark, gray or black. The smaller squares are represented by squares that are lighter in color.
There are many different uses of heatmaps in a website, and they are very important to the people who use them. Among the different types and the uses if the heart maps include:

Web heatmaps :

  • These are heatmaps which are used to display certain areas of the web which are scanned by visitors mostly. In extension, the site owners use this information to understand what the visitors like most; hence assisting in making the necessary decisions about the steps that can be taken to ensure that more traffic is achieved.

Tree map: 

  • This is a two-dimensional partitioning of data which in ordinary cases resembles aheatmap. It has the ability to show the source and the areas that visitors visit most in a website.

Mosaic maps : 

  • These types of heatmaps which represent higher or two ways of data. It is tiled and appears in a way that makes it look like they are organized hierarchically in a mosaic plot. The regions are rectangular shaped and not squarely shaped as it is the norm. It is mainly used to make graphical representations in websites.
It is through the use of heatmaps that you can be able to understand about the visitors that you have recorded and all the things which they like doing on your site. It can be compared to someone watching another person performing a certain activity. Whenever there is a campaign that is being done online, the site owner can make use of heatmaps to understand where the traffic comes from and other related information.
A site heatmap records every mouse that clicks on your web pages. This makes it possible that you get all the necessary statistics through the eyes of your customers. By doing this, you will be able to get more information, which will make to make your site better.
Site heatmaps are graphical illustrations of data where variables represent values of data which are recorded in two-dimensional tables. The origin of the heatmaps is the 2D displays, and its values are represented in a data matrix. In most instances, values that are larger are represented by small squares that are either dark, gray or black. The smaller squares are represented by squares that are lighter in color.
There are many different uses of heatmaps in a website, and they are very important to the people who use them. Among the different types and the uses if the heart maps include:

Web heatmaps:

  •  These are heat-maps which are used to display certain areas of the web which are scanned by visitors mostly. In extension, the site owners use this information to understand what the visitors like most; hence assisting in making the necessary decisions about the steps that can be taken to ensure that more traffic is achieved.

Tree map: 

  • This is a two-dimensional partitioning of data which in ordinary cases resembles a heatmap. It has the ability to show the source and the areas that visitors visit most in a website.

Mosaic maps: 

  • These types of heatmaps which represent higher or two ways of data. It is tiled and appears in a way that makes it look like they are organized hierarchically in a mosaic plot. The regions are rectangular shaped and not squarely shaped as it is the norm. It is mainly used to make graphical representations in websites.
It is through the use of heatmaps that you can be able to understand about the visitors that you have recorded and all the things which they like doing on your site. It can be compared to someone watching another person performing a certain activity. Whenever there is a campaign that is being done online, the site owner can make use of heatmaps to understand where the traffic comes from and other related information.
A site heatmap records every mouse that clicks on your web pages. This makes it possible that you get all the necessary statistics through the eyes of your customers. By doing this, you will be able to get more information, which will make to make your site better.


Hope this post helped.
for any questions,
let me know via comments.


Know More About :
PHP Freelancing India

Thursday, September 15, 2011

How to Translate Text to desired language ?

Just follow these steps and copy & paste the code you can translate text easily.

Step 1 : Make a div with id (id is compulsory)
Like &lt;div id=&quot;content&quot;&gt;Loading…&lt;/div&gt;





Step 2 : Paste the following code to head section under script tag of your webpage.
google.load(“language”, “1″);
function initialize() {
var content = document.getElementById(‘content’);
// Setting the text in the div.
content.innerHTML = ‘&lt;div id=”text”&gt;Place Your Text Here (Hola, me alegro mucho de verte.)&lt;\/div&gt;&lt;div id=”translation”/&gt;’;
// Grabbing the text to translate
var text = document.getElementById(“text”).innerHTML;
// Translate from Spanish to English, and have the callback of the request
// put the resulting translation in the “translation” div.
// Note: by putting in an empty string for the source language (‘es’) then the translation
// will auto-detect the source language.
google.language.translate(text, ‘es’, ‘en’, function(result) {
var translated = document.getElementById(“translation”);
if (result.translation) {
translated.innerHTML = result.translation;
}
});
}
google.setOnLoadCallback(initialize);




Step 3 : And the final Step is paste the following URL in src of script tag.
http://www.google.com/jsapi?key=AIzaSyA5m1Nc8ws2BbmPRwKu5gFradvD_hgq6G0
Above example is translating Spanish to English You can translate as your choice.
Just change the code in
google.language.translate(text, ‘es’, ‘en’, function(result)
es stands for Spanish,
en stands for English
You can find more language code at http://code.google.com/apis/language/translate/v1/reference.html


Hope this post helped,
for any questions let me know by comments.

About

Professional & Experienced Freelance Developer From India, Technologist, Software Engineer, internet marketer and Open Sources Developer with experience in Finance, Telecoms and the Media. Contact Me for freelancing projects.

Enter your email address:

Delivered by FeedBurner