I have tried this code but its not working....what I want is that when I click on "Available" hyperlink a popup form should be opened. I have copied the code below

<? 
        if($GotPro['available']==1)
        {

        echo ($GotPro['PropertyName'].":". '<a href="#" ><script type="text/javascript">window.open(<a href="checkavailability.php" ></a>)</script>Available</a>'); 

        }
        else if($GotPro['available']==0)
        {
        echo ($GotPro['PropertyName'].":". '<a href="#" ><script type="text/javascript">window.open(<a href="checkavailability.php"></a>)</script>UnAvailable</a>'); 
        }
       ?>

Ideally it should work like if user clicks on "Available" hyperlink "checkavailability.php" should open in popup. But it is giving error now

Please someone must help....thanks in advance

Dani AI

Generated

For — the immediate cause is malformed HTML/JS being echoed from PHP. window.open expects a URL string; your echo embeds tags and breaks the quoting, and short PHP tags (<?) can be disabled on some servers. Two practical options:

Minimal fix (quick, uses a popup window). Note the full PHP tag and careful escaping of quotes:

<?php
echo $GotPro['PropertyName'] . ': <a href="#" onclick="window.open(\'checkavailability.php\', \'avail\', \'width=600,height=450\'); return false;">Available</a>';
?>

Better approach (recommended): avoid new windows and use an in-page modal. This won’t be blocked by pop-up blockers and gives a nicer UX (as , and pointed out). Example using jQuery + a Bootstrap-style modal (your page must include jQuery and a modal container with id myModal):

<a href="checkavailability.php" class="open-availability">Available</a>

<script>
$(document).on('click', '.open-availability', function(e){
  e.preventDefault();
  $('#myModal .modal-body').load(this.href);
  $('#myModal').modal('show');
});
</script>

Practical notes and troubleshooting:

  • When loading via AJAX, make checkavailability.php output only the form fragment (not a full HTML document).
  • Check the browser console for syntax errors and the network tab to confirm a 200 response.
  • If you must open a new window, ensure the call happens directly inside the click handler so blockers treat it as a user gesture.
  • Always validate/sanitize server-side and include CSRF protection on forms.

Either approach will work — the popup fix is fastest, but the modal/AJAX pattern is more robust and modern.

Recommended Answers

All 3 Replies

Member Avatar for Member #120589

Have a look at jQuery dialogs or even lightboxes that accept html data. These produce a way to create popups without opening a new browser tab or window - something that could be blocked by the user's browser.

I can recommend HighSlide.

Lightboxes are a fine solution to overlay the form on the existing page. You can use either a button or a text link to open the form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.