Sunday, June 1, 2014

My Day 2 Day jQuery issues collections

Hi Folks!!

In this post I am trying to put my day 2 day jquery problems which I face and fix. Hope you will enjoy reading as much as I enjoyed collecting them for you:

Problem:

     Textbox which should only allow time in HH:MM format and textarea should be disabled till the value is        in correct format.

Solution:

$('#txtTimeInout').keypress(function()
{
var data  = $('#txtTimeInout').val();
var patter = /^\d{2,}:\d{2}:\d{2}$/

if(data.match(patter))
{
 $('#txtarea').prop('disabled',false);
}
else
{
 $('#txtarea').prop('disabled',true);
}
}
)

Problem:

There was a iframe inside a window and inside the page loaded in that window there was a javascript function SaveQuestion() which I was supposed to call from page outside the iFrame in which that window is hosted.

Solution:

So on page on a button click I had to call that method. Following was the solution I implemented/

$('#btnSave').click(function() {
 
   if( windows.frames.length >=1)
 {
    if(typeof(windows.frames[0].SaveQuestion) === "function")
    {
         //Here function is being reference as object so we need to call it using call()
         windows.frames[0].SaveQuestion.call();
    }
 }

});

Hope it will be of help to someone.

Happy Solving!!

No comments:

Post a Comment