Thursday, June 25, 2026

JAVA SCRIPT GET ELEMENT BY ID CONCEPT

 

JavaScript getElementById() with HTML Control – Simple Example with Result

What is getElementById()?

getElementById() is a JavaScript method used to access an HTML element by its id.

Syntax:

document.getElementById("elementId");
  • document → Represents the HTML document.
  • getElementById() → Finds an element using its id.
  • "elementId" → The id of the HTML element.

Example 1: Change Text

HTML + JavaScript

<!DOCTYPE html>
<html>
<head>
<title>getElementById Example</title>
</head>
<body>

<h2 id="heading">Welcome to NRsolution4u</h2>

<button onclick="changeText()">Click Here</button>

<script>
function changeText()
{
document.getElementById("heading").innerHTML = "Welcome to JavaScript!";
}
</script>

</body>
</html>

Result

Before Clicking

Welcome to NRsolution4u

[Click Here]

After Clicking

Welcome to JavaScript!

[Click Here]

Example 2: Read Value from TextBox

<!DOCTYPE html>
<html>
<head>
<title>Textbox Example</title>
</head>
<body>

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

<button onclick="showName()">Show Name</button>

<p id="result"></p>

<script>
function showName()
{
var name = document.getElementById("txtName").value;

document.getElementById("result").innerHTML =
"Your Name is : " + name;
}
</script>

</body>
</html>

Result

If the user types

Nilesh Gupta

and clicks Show Name, the output will be

Your Name is : Nilesh Gupta

Example 3: Change Background Color

<!DOCTYPE html>
<html>
<head>
<title>Color Example</title>
</head>
<body>

<div id="box" style="width:200px;height:100px;background:lightgray;">
</div>

<br>

<button onclick="changeColor()">Change Color</button>

<script>
function changeColor()
{
document.getElementById("box").style.backgroundColor = "orange";
}
</script>

</body>
</html>

Result

Before

+----------------------+
| |
| Gray Box |
| |
+----------------------+

[Change Color]

After Clicking

+----------------------+
| |
| Orange Box |
| |
+----------------------+

Example 4: Enable/Disable Button

<!DOCTYPE html>
<html>
<head>
<title>Button Example</title>
</head>
<body>

<button id="btnSave">Save</button>

<button onclick="disableButton()">Disable Save Button</button>

<script>
function disableButton()
{
document.getElementById("btnSave").disabled = true;
}
</script>

</body>
</html>

Result

Before

[Save]

[Disable Save Button]

After Clicking

[Save]   (Disabled)

[Disable Save Button]

Example 5: Show Selected Option from DropDown

<!DOCTYPE html>
<html>
<head>
<title>Dropdown Example</title>
</head>
<body>

<select id="course">
<option>Java</option>
<option>Python</option>
<option>JavaScript</option>
<option>C#</option>
</select>

<button onclick="showCourse()">Show Course</button>

<p id="output"></p>

<script>
function showCourse()
{
var course = document.getElementById("course").value;

document.getElementById("output").innerHTML =
"Selected Course : " + course;
}
</script>

</body>
</html>

Result

If the selected option is

Python

After clicking Show Course

Selected Course : Python

Common Properties Used with getElementById()

PropertyDescriptionExample
innerHTMLChange HTML contentelement.innerHTML = "Hello";
valueGet or set textbox valueelement.value
style.colorChange text colorelement.style.color = "red";
style.backgroundColorChange background colorelement.style.backgroundColor = "yellow";
disabledEnable or disable controlelement.disabled = true;
srcChange image sourceelement.src = "image.jpg";

Summary

document.getElementById() allows you to access and manipulate HTML elements by their unique id. It is commonly used to:

  • Read user input from text boxes (value)
  • Change text or HTML (innerHTML)
  • Modify CSS styles (style)
  • Enable or disable controls (disabled)
  • Change images (src)
  • Work with dropdowns, buttons, checkboxes, and other HTML elements

It is one of the most fundamental and frequently used methods in JavaScript for interacting with web pages.

Sunday, June 21, 2026

Logout and direct vist to home page

  <a class="dropdown-item" 



href="../default.aspx"> using ../




            <i class="ti-power-off text-primary"></i> 

              Logout 

          </a>

DOMAIN EMAIL PROGRAMMING

USING SYSTEM.NET.MAIL 

  


 SmtpClient smtpClient = new SmtpClient("globeyog.com", 25);



        smtpClient.Credentials = new System.Net.NetworkCredential("globeyog.contact@globeyog.com", "PASSWORD");

        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;


        MailMessage mailMessage = new MailMessage("globeyog.contact@globeyog.com", txtemail.Text);

        mailMessage.Subject = "OTP Verification - GlobeYog Yoga Demo Session Registration";


        mailMessage.Body = @"

                <html>

                <head></head>

                <body style='font-family:Arial, Helvetica, sans-serif; font-size:14px;'>


                <p>Dear Student,</p>


                <p>

                Thank you for registering for the <b>Yoga Demo Session</b> with

                <b>Globeyog</b>.

                </p>


                <p>

                To complete your registration, please verify your email address using the

                One-Time Password (OTP) below:

                </p>


                <p style='font-size:20px; color:#0066CC;'>

                <b>Your OTP: " + n.ToString() + @"</b>

                </p>


                <p>

                This OTP is valid for <b>10 minutes</b>.

                Please do not share it with anyone.

                </p>


                <p>

                If you did not request this registration, please ignore this email.

                </p>


                <p>

                Thank you for choosing <b>Globeyog</b>.

                We look forward to welcoming you to the Yoga Demo Session.

                </p>


                <br />


                <p>

                Regards,<br /><br />


                 


                <b>Team Globeyog</b><br />


                Email:

                <a href='mailto:globeyog.contact@globeyog.com'>

                globeyog.contact@globeyog.com

                </a>

                <br />


                Website:

                <a href='https://globeyog.com/demosession.aspx'>

                www.globeyog.com

                </a>


                </p>


                </body>

                </html>";





          mailMessage.IsBodyHtml = true;

           smtpClient.Send(mailMessage);




      


      


Saturday, June 20, 2026

domain email programming

 SmtpClient smtpClient = new SmtpClient("domainname", 25);


            smtpClient.Credentials = new System.Net.NetworkCredential("domainemail", "password");
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

            MailMessage mailMessage = new MailMessage("domainemail", tomailidcontrol);
            mailMessage.Subject = "Thanks For Registration";
            mailMessage.Body = "Dear User" + "<br>" + "Your OTP is :" + " " + Label5.Text;

            mailMessage.IsBodyHtml = true;
            smtpClient.Send(mailMessage);
            Label1.Text = "OTP Send to email please check Inbox / Spam";

Email Message Draft

ONLY  BODY SECTION  


mail.Body = @"

<html>

<head></head>

<body style='font-family:Arial, Helvetica, sans-serif; font-size:14px;'>


<p>Dear Student,</p>


<p>

Thank you for registering for the <b>Yoga Demo Session</b> with

<b>NRsolution4u</b>.

</p>


<p>

To complete your registration, please verify your email address using the

One-Time Password (OTP) below:

</p>


<p style='font-size:20px; color:#0066CC;'>

<b>Your OTP: " + otp + @"</b>

</p>


<p>

This OTP is valid for <b>10 minutes</b>.

Please do not share it with anyone.

</p>


<p>

If you did not request this registration, please ignore this email.

</p>


<p>

Thank you for choosing <b>NRsolution4u</b>.

We look forward to welcoming you to the Yoga Demo Session.

</p>


<br />


<p>

Regards,<br /><br />


<b>Team NRsolution4u</b><br />


Email:

<a href='mailto:info@nrsolution4u.com'>

info@nrsolution4u.com

</a>

<br />


Website:

<a href='https://www.nrsolution4u.com'>

www.nrsolution4u.com

</a>


</p>


</body>

</html>";

Display checkbox list selected text in label control

  StringBuilder sb = new StringBuilder();


        foreach (ListItem item in CheckBoxList1.Items)

        {

            if (item.Selected)

            {

                sb.Append(item.Text + ", ");

            }

        }

        lblfocdata.Text=sb.ToString();


Display professional message in aspx page

 <table align="center" cellpadding="10" cellspacing="0" border="1" width="700">

        <tr>

            <td align="center">


                  


                <asp:Label ID="lblTitle" runat="server"

                    Text="Registration Successful"

                    Font-Bold="True"

                    Font-Size="X-Large"

                    ForeColor="#a33987">

                </asp:Label>


                <br /><br />


                <asp:Label ID="lblMessage" runat="server">

                </asp:Label>


                <br />


                <asp:Literal ID="Literal1" runat="server" Text="

                    <b>Dear Student,</b><br /><br />


                    Thank you for registering for the <b>Yoga Demo Session</b>.<br /><br />


                    Your registration has been received successfully.

                    Our admin team will verify your registration and send the

                    <b>Google Meet Link</b> along with the

                    <b>Demo Class Schedule</b> to your registered email address

                    within <b>24 hours</b>.<br /><br />


                    Kindly check your <b>Inbox</b> as well as your

                    <b>Spam/Junk</b> folder for the email.<br /><br />


                    Thank you, and we look forward to seeing you in the demo session!<br /><br />


                    <b>Team NRsolution4u</b>">


                 

                </asp:Literal>  <br /> 


                 <a href="Default.aspx" style="color: #666; font-size: 0.9rem;">&#8592; Back</a> <br />

            </td>

        </tr>

    </table>

JAVA SCRIPT GET ELEMENT BY ID CONCEPT

  JavaScript getElementById() with HTML Control – Simple Example with Result What is getElementById() ? getElementById() is a JavaScript...