Thursday, 27 September 2012

Value,text and index (intersting way to handle form elements)

To reset fields we can use: either

val()
text( )
index( )

Generally we usually  access elementseither by following selector

1.using id
2.using group selector like all select elements
3. using class name

but we can also access element with the help of text,index and value

Monday, 24 September 2012

Setting all value in Multiselector

Usually Multiselector doesn't have "all" option value..If it happens then then it's better to set value as "All" if <select> tag is defined in one form page and we render the value to some another page or multiple pages.If we defined it in same page and get on same page then we must have to define the value at declaration time.

Now if we get the value from "Select tag" then the value we are getting like this:

"val1 val2 val3"

and this single must be tokenised to iereate over multiple option values by two approach:
1.Using blank space " "
2.similar string patern.

First approach: (Best approach)
It is safe to use first approach if option string values doesn't have multiple sapces.Therefore try to avoid spaces in option values at definition time till it is not compulsary ( by normalising/trimming/removing spaces see difference in another blog for all three terms ) so that we can easily tokenized by using this approach since after each value there is a space val1 val2 val3 etc.

Second approach:

If it is complulsary to havaing spaces in string and string have some business pattern like (exporting each pdf or xml has an extension .pdf or .xml) therefore we can tokenize over each value as:

for ex- let $All := "0001012-0000002-KOMMUNEKREDIT.xml 0001012-0000003 KOMMUNE KREDIT.xml"
for $Each at $pos in fn:tokenize($All,".xml")[1 to fn:last()-1]
let $EachBatch := fn:normalize-space(fn:concat($Each,".xml"))
return $EachBatch

and then we also need to concat the value over which each string is tokenised.Here we run the loop to the second last element otherwise result would come as: >
0001012-0000002-KOMMUNEKREDIT.xml
0001012-0000003-KOMMUNE KREDIT.xml
.xml

there fore we skip last element.

Third Approach (Only used in following situation)

But what happens if we have compulsion to have spaces in option values and string doesn't have patterns then we have to append some tag identofire with each option value at declaration time or rendered time to differntiate multiple values.

Tuesday, 24 July 2012

Is your hide div is exist in body before you show?

Today I worked on a task in which a hide div has to be display on onclick  event binding.But i was irritated when the div is not showing through show().

Reason: div to be show is not placed in body (because of some if condition or may be it placed in some function that is not called inside body)

Sunday, 22 July 2012

difference in empty() and remove()


  • Empty will remove all the contents of the selection.
  • Remove will remove the selection and its contents.
Consider:
<div>
    <p><strong>foo</strong></p>
</div>

$('p').empty();  // --> "<div><p></p></div>"

// whereas,
$('p').remove(); // --> "<div></div>"

Friday, 20 July 2012

Applying validation using Javascript on event binding always use button rather than submit

Reason : Since while checking negative condition on validation  we must restrict the form to load or submit.To stop loading of form  we can't use submit  button because it loads form atleast once

Thursday, 19 July 2012

return false exit from function

We thought return false only stops the form to submit ..but it is not true actually it stops the function to return the value that function wants to return and also exit the program control from the function (Its a programming principle that when a function return false then control exit the function).

Wednesday, 18 July 2012

Calling two function on single event

We can call multiple functions on a single event such as onclick,onsubmit etc by seperating with semicolon sign ;....like this

<a href="..." onclick="fun1();fun2();">

Alert: -1.Make sure the first function not submit the form otherwise second function will not execute and
2. same thing happens when first function have explicit return statement that time also second function may not execute.