Results 1 to 2 of 2

Thread: dynamic script required

  1. #1
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post dynamic script required

    1) Script Title: Javascript, JQuery

    2) Describe problem: I have made a webpage with jquery with loading header, sidebars, footer and main content window. my site is working ok but i want when someone click a link or form submit in a content div, then the link would open in the same main content div again. I have the js code for a link in sidebars/header to open the same in content div. but do not have if the link is place inside the same div content. Please share the code in any language (PHP, Js, Jquery,etc.).

    My code for opening a link of sidebars/header in content div.
    Code:
    <script type="text/javascript">
    $('#flat').click(function(){
    	$('#step2').load('step3layout.php');
    		});
    </script>
    Thanks in advance.
    Last edited by jscheuer1; 08-21-2013 at 10:07 PM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,130
    Thanks
    44
    Thanked 3,228 Times in 3,189 Posts
    Blog Entries
    12

    Default

    Well, if #flat is a link, you should either return false or prevent the default of the event:

    Code:
    <script type="text/javascript">
    $('#flat').click(function(){
    	$('#step2').load('step3layout.php');
    	return false;
    });
    </script>
    or:

    Code:
    <script type="text/javascript">
    $('#flat').click(function(e){
    	$('#step2').load('step3layout.php');
    	e.preventDefault();
    });
    </script>
    And once you do that you can have the href of #flat be the URL you want:

    Code:
    <script type="text/javascript">
    $('#flat').click(function(e){
    	$('#step2').load(this.href);
    	e.preventDefault();
    });
    </script>
    And once you're doing that, you can do a whole class of links at once:

    Code:
    <script type="text/javascript">
    $('.flat').click(function(e){
    	$('#step2').load(this.href);
    	e.preventDefault();
    });
    </script>
    And the code will take the href from each link that has a class of "flat".

    The browser cache may need to be cleared and/or the page refreshed to see changes.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Replies: 5
    Last Post: 11-19-2011, 02:38 PM
  2. download script required
    By gurmeet in forum PHP
    Replies: 9
    Last Post: 01-02-2011, 04:26 PM
  3. Replies: 4
    Last Post: 07-14-2008, 09:34 AM
  4. Help Required with Bookmark Site Script
    By Jeremy I in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 11-14-2005, 08:50 AM
  5. Form Script required
    By Swallow in forum JavaScript
    Replies: 0
    Last Post: 09-12-2005, 10:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •