Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Thursday, 29 December 2016

how to find vowels in a string in javascript

how to find vowels in a string in javascript

Introduction:

Here I will explain how to find vowels in a string in  javascript. In javascript such a not inbuilt function to get how to find vowels in a string in javascript so I have create this small function to how to find vowels in a string in javascript . It is easiest way to  how to find vowels in a string in javascript.

In previous post I explained System.Array' does not contain a definition for 'Count' how to access session in class c# how to create chat application in asp.net using c# sql query to get daily count and many article about Asp.net javascript and C#

Search:

how to find vowels in a string in javascript


Javascript function:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function VowelsData() {
    var Data = document.getElementById('txtData').value;
    if (Data == "")
    {
        alert('Enter value to check find vowels in a string');
        return;
    }
    var Count = 0;
    var Vowels = "";
    for (var Counter = 0; Counter < Data.length; Counter++) {
        if (Data.charAt(Counter).match(/[a-zA-Z]/) != null) {
            if (Data.charAt(Counter).match(/[aeiouAEIOU]/)) {
                Vowels = Vowels + Data.charAt(Counter);
                Count++;
            }
        }
    }
    if (Vowels == "")
    {
        Vowels = "Oops No Vowels";
    }
    document.getElementById('lblVowels').innerHTML = Vowels;
    document.getElementById('lblVowelsCount').innerHTML = Count;
}



Complete Example for how to find vowels in a string in javascript:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html>
<head>
    <title>how to find vowels in a string in javascript</title>
    <script>
function VowelsData() {
    var Data = document.getElementById('txtData').value;
    if (Data == "")
    {
        alert('Enter value to check find vowels in a string');
        return;
    }
    var Count = 0;
    var Vowels = "";
    for (var Counter = 0; Counter < Data.length; Counter++) {
        if (Data.charAt(Counter).match(/[a-zA-Z]/) != null) {
            if (Data.charAt(Counter).match(/[aeiouAEIOU]/)) {
                Vowels = Vowels + Data.charAt(Counter);
                Count++;
            }
        }
    }
    if (Vowels == "")
    {
        Vowels = "Oops No Vowels";
    }
    document.getElementById('lblVowels').innerHTML = Vowels;
    document.getElementById('lblVowelsCount').innerHTML = Count;
}
    </script>
</head>
<body>
    <h1>how to find vowels in a string in javascript</h1>
    <div style="padding: 50px">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
    <td>Enter Input :
    </td>
    <td>
        <input type='text'  id='txtData' >
    </td>
</tr>
    <tr>
    <td colspan="2">
        <input type='button' value='Find Vowels' onclick="VowelsData();">
    </td>
</tr>
<tr>
    <td>Total Vowels Count :
    </td>
    <td>
        <label id="lblVowelsCount"></label>
    </td>
</tr>
<tr>
    <td>Total Vowels :
    </td>
    <td>
            <label id="lblVowels"></label>
    </td>
</tr>
</table>
    </div>
</body>
</html>

You might also like

1. file type validation in jquery
2. file size validation in jquery
3. calling web service without adding web reference
4. How to bind CheckBoxList from database
5. How to bind DropdownList from database

/>

get month number from month name using javascript

get month number from month name using javascript

Introduction:

Here I will explain how to get month number from month name using javascript. In javascript such a not inbuilt function to get month number from month name so I have create this smaal function to get month number from month name using javascript. It is easiest way to convert month name to month number in javascript.

In previous post I explained System.Array' does not contain a definition for 'Count' how to access session in class c# how to create chat application in asp.net using c# sql query to get daily count and many article about Asp.net javascript and C#

Search:

how to get month number from month name using Javascript
get month number from month name


Eample:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>get month number from month name using javascript</title>
    <script>
        function getMonthFromName(MonthName) {
            var Month = 1;
            switch (MonthName) {
                case "January":
                    Month = 1;
                    break;
                case "February":
                    Month = 2;
                    break;
                case "March":
                    Month = 3;
                    break;
                case "April":
                    Month = 4;
                    break;
                case "May":
                    Month = 5;
                    break;
                case "June":
                    Month = 6;
                    break;
                case "July":
                    Month = 7;
                    break;
                case "August":
                    Month = 8;
                    break;
                case "September":
                    Month = 9;
                    break;
                case "October":
                    Month = 10;
                    break;
                case "November":
                    Month = 11;
                    break;
                case "December":
                    Month = 12;
                    break;
            }
            return Month;
        }
        function getMonthNumber() {
            var MonthNo = getMonthFromName(document.getElementById('txtMonthName').value);
            document.getElementById('lblMonthNumber').innerHTML = MonthNo.toString();
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h1>get month number from month name using javascript</h1>
            <input type="text" id="txtMonthName" />
            <input type="button" value="Get Month Number" onclick="getMonthNumber();" />
            <br />
            Month Number is:
            <label ID="lblMonthNumber"></label>
        </div>
    </form>
</body>
</html>

You might also like

1. file type validation in jquery
2. file size validation in jquery
3. calling web service without adding web reference
4. How to bind CheckBoxList from database
5. How to bind DropdownList from database

Friday, 22 April 2016

file size validation in jquery


Introduction:

Here I will explain how to validate file size using Jquery or Javascript. Sometimes required  validation like File size cannot be more than 2Mb or 5MB otherwise alert to user "File size cannot be more than 2Mb or 5MB"

Description: 

In previously post I explained to  
file type validation in jquery
Change the column name or datatype or size in sql server
How to set or get textbox value using Javascript or Jquery
Server does not support secure connections  
textbox allow only characters javascript
button click event not firing in asp.net c#

And now here I explain to how to validate file size using Jquery or Javascript in asp.net.

Now copy the following javascript code in your page.


function IsFileValid() {

        var objFileUpload = document.getElementById("fuContentImage");
        if (objFileUpload.value != null || objFileUpload.value != "") {
        var file;
        file = objFileUpload.files[0];
      

 if (file.size > 2097152) //file.size returns Bytes of the file
        {
                alert("File size cannot be more than 2Mb.");
                return false;
        }
 
    }
}


And copy this html in your page


<h1>how to validate File size cannot be more than 2Mb or 5MB using Jquery or Javascript</h1>

<input type="file" name="Image" id="fuContentImage" />  

<input type="submit" onclick="return IsFileValid();" value="Add" class="btn btn-success" style="width:200px" />

file type validation in jquery


Introduction:

Here I will explain how to validate file type like JPG,PNG or JPEG using Jquery or Javascript. Sometimes required this type of validation like upload only  JPG,PNG or JPEG file otherwise alert to user "file type is not valid to upload "

Description: 

In previously post I explained to  
Change the column name or datatype or size in sql server
How to set or get textbox value using Javascript or Jquery
Server does not support secure connections  
textbox allow only characters javascript
button click event not firing in asp.net c#

And now here I explain to how to validate file type like JPG,PNG or JPEG using Jquery or Javascript in asp.net.

Now copy the following javascript code in your page.



function IsFileValid() {

        var objFileUpload = document.getElementById("fuContentImage");
        if (objFileUpload.value != null || objFileUpload.value != "") {
            var file;
            file = objFileUpload.files[0];
            if ((file.name.split('.').pop().toLowerCase()) == "png" || (file.name.split('.').pop().toLowerCase()) == "jpg" || (file.name.split('.').pop().toLowerCase()) == "jpeg" || (file.name.split('.').pop().toLowerCase()) == "bmp") {

            }
            else {
                alert("Please upload png,jpg or jpeg image only.");
                return false;
            }
           
           
        }
        return true;
    }


And copy this html in your page




<h1>how to validate file type like JPG,PNG or JPEG using Jquery or Javascript</h1>

<input type="file" name="Image" id="fuContentImage" />  

<input type="submit" onclick="return IsFileValid();" value="Add" class="btn btn-success" style="width:200px" />






 


Tuesday, 5 April 2016

How to set or get textbox value using Javascript or Jquery ?

Introduction:

Here I will explain How to set textbox value using Jquery, How to get textbox value using Jquery, How to set textbox value using Javascript, How to get textbox value using Javascript. If you want to How to set or get textbox value using Javascript or Jquery then copy following code in your page.

Description: 

In previously post I explained to  
file type validation in jquery
Change the column name or datatype or size in sql server
How to set or get textbox value using Javascript or Jquery
Server does not support secure connections  
textbox allow only characters javascript
button click event not firing in asp.net c#

And now here I explain to How to set textbox value using Jquery, How to get textbox value using Jquery, How to set textbox value using Javascript, How to get textbox value using Javascript in asp.net.

Now copy the one by one following javascript code in your page.


How to set or get textbox value using Javascript or Jquery ?

How to set textbox value using Javascript


function setValueJavascript() {
        document.getElementById('txtName').value = "Set Value To textbox using javascript";
    }

How to get textbox value using Javascript

function getValueJavascript() {
        var Name = document.getElementById('txtName').value;
        alert(Name);
    }

How to set textbox value using Jquery

function setValueJquery() {
        $("#txtName").val('Set Value To textbox using Jquery');
    }

How to get textbox value using Jquery

function getValueJquery() {
        var Name = $("#txtName").val();
        alert(Name);
    }

Here full example of How to set textbox value using Javascript, How to get textbox value using Javascript How to set textbox value using Jquery and How to get textbox value using Jquery

Example:


<!DOCTYPE html>
<html>
<head>
    <title>How to set or get textbox value using Javascript or Jquery</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">
    </script>
    
    <script>

    function setValueJavascript() {
        document.getElementById('txtName').value = "Set Value To textbox using javascript";
    }

    function getValueJavascript() {
        var Name = document.getElementById('txtName').value;
        alert(Name);
    }

    function setValueJquery() {
        $("#txtName").val('Set Value To textbox using Jquery');
    }

    function getValueJquery() {
        var Name = $("#txtName").val();
        alert(Name);
    }
    </script>
</head>
<body>
    <h1>How to set or get textbox value using Javascript or Jquery</h1>

    Enter Name: <input type="text" id="txtName" />

    <br /><br />
    <input type="button" value="Set Value Javascript" onclick="setValueJavascript()" />
    <input type="button" value="Get Value Javascript" onclick="getValueJavascript()" />
    <input type="button" value="Set Value Jquery" onclick="setValueJquery()" />
    <input type="button" value="Get Value Jquery" onclick="getValueJquery()" />
</body>
</html>

How to get Value of All textbox of particalar Div

Some times required to get Value of All textbox of particalar Div and inserting or doing some operation to these texboxes value. so I have added this complete code to get Value of All textbox of particalar Div or get Value of multiple textbox of particalar Div using Jquery.

Example:


<!DOCTYPE html>
<html>
<head>
    <title>How to get Value of All textbox of particalar Div</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">
    </script>

    <script>
        function GetValue() {
            var Contain = "";
            $("#divRegsiter :text").each(function () {
                alert($(this).val());
            });
        }
    </script>
</head>
<body>
    <h1>How to get Value of All textbox of Div</h1>

    <div id="divRegsiter">
        Enter Name: <input type="text" id="txtName" /><br />
        Enter User Name: <input type="text" id="txtUserName" /><br />
        Enter Email: <input type="text" id="txtEmail" /><br />
    </div>
    <div id="divLogin">
        <p>Not getting this textbox value when you click on button, because 
        this is exist in different Div</p>

        Enter Name: <input type="text" id="txtNameLogin" /><br />
    </div>
    <br /><br />
    <input type="button" value="Get All Textboxes Value" onclick="GetValue()" />
</body>
</html>



Asp.net tutorials