jQuery link method in ASP.NET

The jQuery link() method is used to display a string as a hyperlink or you can say that it links form fields to an object.
  • 1527
 

The jQuery link() method is used to display a string as a hyperlink or you can say that it links form fields to an object. Any changes to the form field values are automatically represented in the object. It returns the string embedded in the <a> tag.

Syntax

$ string.link (url)

The following example shows how you can link all the input elements of a form to an object.  

<html>
<
head><title>jQuery link method</title>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <style type="text/css">
        .style1
        {
            font-family: Verdana;
            font-size: small;
        }
    </style>

</
head>
<
body style="background-color: #F3F3E9">

<form>
    <div style="font-family: Verdana; font-size: small; font-weight: bold;">
        First Name:&nbsp;
        <input type="text" name="firstName" style="width: 189px" />
    </div>
    <div style="font-family: Verdana; font-size: small; font-weight: bold;">
        Last Name:&nbsp;
        <input type="text" name="lastName" style="width: 189px" />
        <br />
    </div>

</
form>
    <span class="style1"><strong>
    <br />
      User First Name:  </strong></span> <span id="objFirst"></span><strong>
    <br class="style1"/>
    </strong><span class="style1"><strong>User last Name</strong></span><strong>:
    </strong> <span id="objLast"></span> 

<strong>

  <script>
    var person = {};
    $("form").link(person);
       $("#objFirst").link(person, {
        firstName: {
            name: "objFirst",
            convertBack: function (value, source, target) {
                $(target).text(value);
            }
        }
    });
    $("#objLast").link(person, {
        lastName: {
            name: "objLast",
            convertBack: function (value, source, target) {
                $(target).text(value);
            }
        }
    });

  </
script>   
</
strong>

</body>
</
html>

Output



 link1.gif

Now enter the user name and see how does it append to an object as shown in below the figure.

link2.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.