Results 1 to 4 of 4

Thread: combo vox load external file into html div

  1. #1
    Join Date
    Nov 2008
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default combo vox load external file into html div

    Hello:

    I am trying to load an external file, in this case, php code, into an html div based on what is selected from a combo box. The code I have loads opnes the file, but I would like it opened in the div "contents". Everything I have searched for wants to populate the combo box, I want to populate the div. Can anyone help? This is what I have so far ...



    Code:
    <html>
    <head>
    <title>Untitled</title>
    <script type="text/javascript">
    <!--
    function nav(f){
      var theUrl = f.jump.options[f.jump.selectedIndex].value ;
      if (theUrl != ""){
          location.href = theUrl ;
      }
    }
    //-->
    </script>
    </head>
    <body>
    <form action="no_value">
    <select name="jump" onchange="nav(this.form)">
    <option value="">----- Select A Page -----</option>
    <option value="test1.php">Home</option>
    <option value="test2.php">Page 2</option>
    <option value="test3.php">Page 3</option>
    </select>
    </form>
    <div id="contents"></div>
    </body>
    </html>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Untitled</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script>
    jQuery.ajaxSetup({cache: false}); // This line can be removed. But keeping it makes sure that cached copies of the external pages are never fetched
    jQuery(function($){
    	function nav(){
    		var theUrl = this.value ;
    		if (theUrl != ""){
    			$('#contents').load(theUrl);
    		}
    	}
    	$('select[name="jump"]').change(nav);
    });
    </script>
    </head>
    <body>
    <form action="no_value">
    <select name="jump">
    <option value="">----- Select A Page -----</option>
    <option value="test1.php">Home</option>
    <option value="test2.php">Page 2</option>
    <option value="test3.php">Page 3</option>
    </select>
    </form>
    <div id="contents"></div>
    </body>
    </html>
    - John
    ________________________

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

  3. #3
    Join Date
    Nov 2008
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    John, THANKS !!! What might come naturally to you was a huge struggle for me and it works perfectly. Basically what happens is those .php files are scripts to run a MySQL database and the "contents" div are the results. Should I run a validation script to ensure that specific files are run or is this safe as is. Just wondering if it is possible to somehow cheat the .html file into running other scripts?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There's nothing you can do to prevent what browsers will allow, even on a plain page that has no javascript. So I would say there's nothing to worry about. That said, it might be worth considering what I wrote just a little while back about this, before I had time to think further:

    "Hmm, the code in my post loads the pages via AJAX (using jQuery's built in AJAX routines). That guarantees that the page loaded into the content div will be from the same server as the page with the content div on it. But, it is possible that, if a user is savvy and knows the addresses of other available pages on your server, they could load one of those into the content div. But, they would have to go to considerable trouble to do so, and still would not be able to view any page on your server that they wouldn't be able to navigate to directly.

    If you're following me, then you will understand why I say no - unless doing that could provide them with some kind of advantage over you. They would not be able to fool others by making them have that experience. They could do it themselves while viewing your page and/or instruct others how to do that. But due to the same domain policy of AJAX they could not put their own page in there for anyone, not even for themselves. And could not even put in another page from your domain for someone else without that other person's knowledge."

    So, if any of that seems a threat - though I can't imagine it would be, best to take down any pages you don't want available to the public. But again, this would be true even without any sort of javascript.
    Last edited by jscheuer1; 12-02-2014 at 02:27 AM. Reason: add perspective
    - John
    ________________________

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

Similar Threads

  1. Replies: 4
    Last Post: 11-06-2010, 12:43 AM
  2. Load an random external HTML into a Div
    By garret in forum JavaScript
    Replies: 3
    Last Post: 10-17-2010, 06:50 PM
  3. Replies: 0
    Last Post: 12-09-2009, 03:41 PM
  4. Load external file - simple question
    By mtran in forum JavaScript
    Replies: 1
    Last Post: 10-13-2009, 03:55 AM
  5. load content from external file
    By genius_supreme in forum JavaScript
    Replies: 1
    Last Post: 07-29-2006, 09:35 AM

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
  •