views:

68

answers:

1

Hello,

I want to open a facebox modal after some javascript validation. I am using this code:

<script type="text/javascript" src="facebox.js"></script>

Script:

function validatePage()
{
  if(document.getElementById('username').value == '')
  {
        alert('Please enter Username');
        return false;
  }

  //My Code should go here
}

Markup:

<a href="pagename.php" rel="facebox" onclick="javascript:validatePage()">Click Me</a>

For some reason the facebox modal does not open...instread the page is opening in a new window.

Any suggestion will be highly appreciated.

Thanks in advance

A: 

Is your onclick overriding the Facebox functionality? I don't know if it would, but that's a thought. Have you tried manually triggering the function instead?

function validatePage(e)
{
  if(document.getElementById('username').value == '')
  {
      alert('Please enter Username');
  } else {
      $.facebox({ajax: $(e).attr("href")});
  }
  return false;
}

I just passed the element to the function, to make that extend to other things. You'd just say "javascript:validatePage(this)" in your onclick.

Ben Saufley
And you'd remove the facebox rel, if you did that. I presume.
Ben Saufley
Oh also if you're using jQuery you can just say $("#username").val() instead of the whole document.getElementById('username').value thing. Just sayin'.
Ben Saufley
thanks man for all these info...
Deepak Ranjan Jena
No problem! Would you mind voting it up, or if it's correct, marking it as the correct answer?
Ben Saufley