Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Sunday, November 28, 2010

Jquery - Dynamically add TextBox and Consolidate Text Data for Server Submission

Intro:
A function that allows user to add new TextBox (on demand) and then when submit, all Textbox data is consolidated and hidden form field value set to the consolidated Data.

The HTML:

Type your Questions and click on 'add question' to add more ratings question.
<div>
    <div id="divTextBox">
        Question No. 1 <input type="text" id="txt_1" class="svTxt" size="80" />
    </div>

    <br />
        <a href="#" id="addQuestionLink">[ + ] Add Question</a>
</div>

<hr />

<div id="DebugSection">
        <asp:HiddenField ID="hdnData" runat="server" />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit To Server" />
        <hr />
        Server reads the hidden field and writes :<br /> <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>


The JQuery:
<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        var txtCount = 1; //By default there is only 1 text box
        var svTextAll = ''; //consolidated questions


        //
        // Click ADD QUESTION function
        //  On span '#addTxt' click
        //
        $("#addQuestionLink").bind("click", function (e) {
            txtCount++;
            $("#divTextBox").append("<br />Question No. " + txtCount + " <input type='text' id='txt_" + txtCount + "' class='svTxt' size='80' />");
        });


        //
        // Click Submit button
        // Consoldate quesitons and updates the hidden form field value and
        //  postback to server for .cs to process
        //

        $("#btnSubmit").bind("click", function (e) {
            $(".svTxt").each(function (i) {
                svTextAll = svTextAll + '<|>' + $(this).attr('value');
            });

            //write data to hidden field.
            $("#hdnData").val(svTextAll);
        });

    });
    </script>

Friday, September 17, 2010

Jquery Common Operations

1) Get Custom Attribute & Open Popup
this get the custom attribute set to a div opens a popup using that custom attribute as the URL
where the Div is


// Action for when the app icon is clicked
            $(".appIcon").click(function () {
                var url = $(this).attr('takelink');
                window.open(url, '', 'width=800, height=600', '');
            });


2) Change mouse cursor to 'pointer' on rollover of a div
this uses .css (to add a css to the selected div)

//change the pointer
            $(".appIcon").mouseenter(function () {
                $(this).css('cursor', 'pointer');
            });

3) Append all URL links and add Back Link (using .each)

//get all take links
//Updates all a href where the class is .title and append the href url.
$("a.title").each(function() {
            var currHref = $(this).attr("href");
            $(this).attr("href", currHref + "&backURL=" + window.location.pathname);
});

4) Getting Value from TextArea

        $(document).ready(function () {
            $("#lnkSubmit").click(function () {
                /* get the data entered and send it via ajax*/
                var ddata = $("#newsFeedTxt").val();
                alert(ddata);
            });
        });

5) To check if a 'checkbox' is checked

if ($("#myCheckBox").attr('checked') == true)
{
//your action
}



Tuesday, August 24, 2010

JQuery & Checkboxes


 Basically
  • Creating Checkbox
  • Applying custom attribute to checkbox
  • Applying unique ID to checkbox
  • Checking of the checkbox is checked
  • Applying style to checkbox
  • checking a  checkbox
all via JQuery



   1:  <script language="javascript" type="text/javascript">
   2:   
   3:      $(document).ready(function () {
   4:          var cbID = 0;
   5:          var totalPeriod = 11;
   6:   
   7:          //on rollver create checkbox
   8:          $("#activity0").bind("mouseenter mouseleave", function (e) {
   9:              cbID++;
  10:              $(this).append("<input type='checkbox' id='myCB_" + cbID + "' cbtype='firstOne'/>");
  11:          });
  12:   
  13:          for (var x = 1; x < totalPeriod; x++) {
  14:              $("#activity").append("Period#" + x + " <input type='checkbox' id='myCB_" + x + "' cbtype='firstOne'/>");
  15:          }
  16:   
  17:          //when btn is clicked
  18:          $("#processBtn").bind("click", function (e) {
  19:              alert("Showing All CHeckBox")
  20:              $("form input:checkbox").each(function (i) {
  21:                  alert($(this).attr('id') + " " + $(this).attr('cbType') + " - " + $(this).attr('checked'))
  22:              });
  23:          });
  24:   
  25:          //toggle style on CB
  26:          $("form input:checkbox").bind("focus", { cssStyle: "focusCB" }, setCSS);
  27:          //$("form input:checkbox").bind("blur", { cssStyle: "blurCB" }, setCSS);
  28:   
  29:   
  30:          function setCSS(e) {
  31:              var cbID = "#" + e.target.id;
  32:              $(cbID).toggleClass(e.data.cssStyle);
  33:              $(cbID).attr("disabled", "disabled");
  34:              $(cbID).attr("checked", "checked");
  35:              $("#checkStatus").append("<br>You Checked: " + $(cbID).attr("id"));
  36:          }
  37:      });
  38:   
  39:  </script>
  40:   
  41:  <div id="activity">
  42:      Activity Area
  43:      <br />
  44:    
  45:      </div>
  46:      <input type="checkbox" disabled="disabled" />
  47:      <input type="button" id="processBtn" value="go" />
  48:   
  49:      <div id="checkStatus">
  50:      Status
  51:     
  52:      </div>

Wednesday, August 18, 2010

Load RSS Feed (using Jquery) by parsing it from ASP.NET Method

Jquery (with Ajax & Data integration) Lesson 1
Im having ideas of social events being constantly updated to XML Feed, and users able to see the updates via this method, anyways, ill quote from the article:-
To that end, I’m going to walk you through these four steps to effectively implementing a client side Repeater, using ASP.NET AJAX and jQuery:
  • Create an RSS Reader page method to return JSON data to the client.
  • Call that page method with jQuery.
  • Use the returned data to build a table on the client side.
  • Improve upon the table creation with a templating plugin.
Use jQuery and ASP.NET AJAX to build a client side Repeater


Jquery Lesson 2

Only Simple stuff from me, just found this nice tutorial, that shows how to acquire data via 'get' or 'post' via jquery. Im amazed by its simplicity, check it out.

Using jQuery in ASP.Net AJAX Applications – Part 1



   1:  <script>
   2:  $(document).ready(function () {
   3:      $("#txtNoTic").change(function () {
   4:          $("#Error1").html("");
   5:          var ticketRequest = $("#txtNoTic").val();
   6:          $.get("getData.aspx", function (result) {
   7:              var ticsAvail = parseInt(result);
   8:              if (ticketRequest > ticsAvail) {
   9:                   $("#Error1").html("only " + ticsAvail + " are available.");
  10:                   $("#Error1").css("color", "red");
  11:              }
  12:              else {
  13:                   $("#Error1").html("Tickets available, pls proceed confidently");
  14:                   $("#Error1").css("color", "green");
  15:              }
  16:         });
  17:     });
  18:  });
  19:  <script>



Jquery Templating
pretty interesting technology, i just find it style so similar to classic asp, except this is all done in client side js! Altho it seems to be able to do bit more then classic asp.
To get started

1) download the Jquery template files [download]
*note the download button is on top*

2) read a tutorial site [view]

3) read a resource on it [view]

4) MSDN Article on Jquery
Explore Rich Client Scripting With jQuery, Part 1
Explore Rich Client Scripting With jQuery, Part 2
Web Site Improvements Using jQuery and jQuery UI
Predictive Fetch with jQuery and the ASP.NET Ajax Library

Monday, August 16, 2010

Making (what it appears to be AJAX Jquery calls while passing in Parameters)

1) Page.aspx


   1:  <html>
   2:  <head runat="server">
   3:  <title></title>
   4:  <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
   5:  <script language="javascript" type="text/javascript">
   6:   
   7:  $(document).ready(function () {
   8:      // Add the page method call as an onclick handler for the div.
   9:      $("#Result").click(function () {
  10:          $.ajax({
  11:          type: "POST",
  12:          url: "JqueryTest01.aspx/GetDate",
  13:          data: "{'name':'Ali'}",
  14:          contentType: "application/json; charset=utf-8",
  15:          dataType: "json",
  16:          success: function (msg) {
  17:              // Replace the div's content with the page method's return.
  18:              $("#Result").text(msg.d);
  19:              }
  20:          });
  21:      });
  22:  });
  23:  </script>
  24:  </head>
  25:      <body>
  26:          <form id="form1" runat="server">
  27:              <div id="Result">Click here for the time.</div>
  28:          </form>
  29:      </body>
  30:  </html>


2) page.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.Services;

namespace MyBlog
{
public partial class JqueryTest01 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}


[WebMethod]
public static string GetDate(string name)
{
return name + " - " + DateTime.Now.ToString();
}
}
}






points to take note.
1. scribe fire SUCK when u want to share code!... i need to find a better way!

Thursday, June 17, 2010

Jquery Exploration Day 1

Getting my Tutorials from: http://dotnetslackers.com/articles/ajax/using-jquery-with-asp-net.aspx
Notes:

  $(‘p.note’)  returns all <p>  elements whose class name is note;
  $(‘p#note’) returns the <p> element whose id is note;
  $(‘p’) returns all <p> elements


1. drag and sort list example
http://tutorialzine.com/2009/11/jquery-sort-vote/

2. a good idea for Content
http://tutorialzine.com/2009/11/beautiful-apple-gallery-slideshow/



Tuesday, November 24, 2009

CSS Basic Crash Course.

Guess what, i dont know the basics of CSS but because of wizards in many apps & free templates that i use, managed to get around this problem, but when i need precise control, its a time consuming guessing game.

So this is my crash course on CSS Basic (with some text taken from : http://www.w3schools.com/css/css_id_class.asp)

1. id Selector (e.g #style1)
  • specify a style for a single, unique element
  • uses the id attribute of the HTML element, and is defined
    with a "#".
Example:
CSS: #para1{text-align:center;color:red}
HTML: <p id="para1">Hello World!</p>


2. class Selector (e.g .style1)

  • to specify a style for a group of elements. Unlike the id
    selector, class selector is used on several elements.
  • allows you to set a particular style for any HTML elements with the same class.
Example:
CSS: .center{text-align:right;}

HTML:
<h1 class="center">Center-aligned heading</h1>
<p class="center">Center-aligned paragraph.</p>


3. Grouping Selectors
  • there are often elements with the same style, To minimize the code, you can group selectors.
  • Separate each selector with a comma.
Example:
CSS: h1,h2,p {color:green;}


4. Nesting Selectors

  • means apply a style for a selector within a selector
Example:
CSS:
p {color:blue; text-align:center;}
.marked {background-color:blue}
.marked p {color:white;}

HTML:
<p>Text is a blue, center-aligned </p>
<div class="marked"><p>This p element will be white and background will be blue</p></div>


Another Example of Nesting
CSS:
.mydiv {position: absolute;bottom: 10px;right: 10px;}
.mydiv> p, a {color:green}

HTML:
<div class="mydiv"> test <p>some p tag</p>
<a href="#">test link</a>
</div>


5. Fixed Positioning
  • element position is fixed relative to the browser window. and will not move even if the window is scrolled
Example:
CSS: .fixedPos {position: fixed; top: 10px; right: 30px;}
HTML: <div class="fixedPos">Item with Fixed positioning</div>


6. Relative Position
  • its like (off-setting) the position of an element (to its left, right, top, bottom) but a number of px
  • alt explanation: element is positioned relative to its normal position / element can be moved with reference to its current normal position.
Example:
CSS:
h2.pos_left { position:relative;left:-20px;}

h2.pos_right {position:relative;left:20px;}

HTML:
<h2 class="pos_left">This heading is moved left according to its normal position</h2>
<h2 class="pos_right">This heading is moved right according to its normal position</h2>


7. Absolute Positioning
  • An absolute position element is positioned relative to the first parent element that has a position other
    than static. If no such element is found, the containing block is <html>:
  • Absolutely positioned elements are removed from the normal flow. The document and other elements behave like the absolutely positioned element does not exist.
  • Absolutely positioned elements can overlap other elements.

Example:
h2 {position:absolute;left:100px;top:150px;}
HTML: <h2>This is a heading with an absolute position</h2>


7.1. Left and right Alignment.
  • A method to align elements using absolute position
CSS:
.alignBottomright {position:absolute; right:100px; bottom:10px;width:300px;background-color:#b0e0e6;}

HTML:
<div class="alignBottomright">this div will be placed 10px from bottom of the page and 100px from right of page</div>


8.1 Pseudo Class: lang
this modifys the <q> tag, changing it from default " as quote tags to something else, and we can have multiple function for it.

CSS:
q:lang(tilder) {quotes: "~" "~";}
q:lang(carot) {quotes: "^" "^";}

HTML:
<p>Some text <q lang="carot">A quote in a paragraph</q> Some text.</p>
<p><q lang="tilder">Internet Explorer 8 (and higher)</q> supports the :lang pseudo class
if a !DOCTYPE is specified.</p>

8.2 Pseudo Class: focus (must SEE!)
Note: Internet Explorer 8 (and higher) supports the :focus pseudo-class if a !DOCTYPE is specified.
  • when you click on an element and that element is in focus, then apply css to that element
  • The :focus pseudo-class adds special style to an element that has keyboard input focus.
  • unfortunately, only works for 'input' elements ONLY 
Example:
CSS: input:focus {background-color:yellow;}

HTML:
<form>Name: <input type="text" name="lname" /></form>

8.3 Pseudo Class: different style for different links

Example
CSS:
a.one:link {color: #ff0000}
a.one:visited {color: #0000ff}
a.one:hover {color: #ffcc00}

a.two:link {color: #ff0000}
a.two:visited {color: #0000ff}
a.two:hover {font-size: 150%}


HTML:
<p><b><a class="one" href="default.asp" target="_blank">This link changes color</a></b></p>
<p><b><a class="two" href="default.asp" target="_blank">This link changes font-size</a></b></p>


8.3 Pseudo Class, :firstchild
  • style is applied to first match in the element.
Example:Match the first <i> element in all <p> elements

CSS: p > i:first-child {font-weight:bold }

HTML:
<p>I am a <i>strong</i> man. I am a <i>strong</i> man.</p>
<p>I am a <i>strong</i> man. I am a <i>strong</i> man.</p>



9. Pseudo Element.
  • :after - Adds content after an element
  • :before - Adds content before an element
  • :first-letter - Adds a style to the first character of a text
  • :first-line - Adds a style to the first line of a text
Example:
CSS:
p:first-letter {color:#ff0000;font-size:xx-large;}
p:first-line {color:#0000ff;font-variant:small-caps;}
p:before {content:url(smiley.gif);}
p:after{content:url(smiley.gif);}

10. Attribute Selector
we can define custom attributes for the html elements

Example:
CSS: [redText] {color:blue;}

HTML:
<h1 redText>Hello world</h1>
<div redText>hi there im a div</div>
<a redText href="http://w3schools.com">W3Schools</a>



Example 2: (Attribute and Value Selector)
CSS: [title=W3Schools]{border:5px solid green;}
HTML: <h1 title="W3Schools">Hello world</h1>


Example 3: (wildcard / multiple values) - The example below styles all elements with a title attribute that contains a specified value. This works even if the attribute has space separated values:

CSS: [title~=hello]{color:blue;}
HTML:
<h1 title="hello world">Hello world</h1>
<p title="student hello">Hello CSS students!</h1>


Example 4: form styling

<style>
input[type="text"] { width:150px; display:block; margin-bottom:10px; background-color:yellow;}
input[type="button"] { width:120px; margin-left:35px; display:block;}
</style>
</head> <body>

<form name="input" action="" method="get">
Firstname:<input type="text" name="Name" value="Peter" size="20">
Lastname:<input type="text" name="Name" value="Griffin" size="20">
<input type="button" value="Example Button">

11. Example of Transparent Div on an Image.

URL: http://www.w3schools.com/css/tryit.asp?filename=trycss_transparency

Sample code:
CSS:
div.background {  width: 500px;  height: 250px;  background: url(klematis.jpg) repeat;  border: 2px solid black;}
div.transbox {  width: 400px;  height: 180px;  margin: 30px 50px;  background-color: #ffffff;  border: 1px solid black;  filter:alpha(opacity=60);  opacity:0.6;}
div.transbox p {  margin: 30px 40px;  font-weight: bold;  color: #000000;}


HTML:
<div class="background">
<div class="transbox">
<p>This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
</p>
</div>
</div>


Monday, July 06, 2009

Jquery Tutorials

1. one recommeded by Polymorphic podcast is:
http://www.west-wind.com/presentations/jquery/
(this is more for those who use asp.net)

2. there is a API for jquery
http://dj.codeplex.com/
DJ - jQuery Web Contorls for ASP.NET is a OpenSource project. It makes easier for developer to using jQuery and jQuery ui on ASP.NET developing.It not only provides cool web controls for jQuery but also provides a lightweight framework to write jQuery plugin Server Controls super fast!}
WOW!!!!


Sunday, December 14, 2008

jquery for beginners

im just starting to explore jquery, started sometime back but kind of gave up, this :
http://nettuts.com/articles/web-roundups/jquery-for-absolute-beginners-video-series/

is pretty ok, video tutorials from basics about jquery