Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: Pass value to php with ajax

  1. #21
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,941
    Thanks
    43
    Thanked 3,193 Times in 3,156 Posts
    Blog Entries
    12

    Default

    I just gave document.write as an example. There are lots of ways. Another is:

    Code:
    document.body.innerHTML = 'Whatever';
    Besides that, disabling document.write would disable it for it's legitimate uses as well.

    And I was playing around with the iframe idea a bit. But then I realized you can do the same thing with it by prefacing your other code with:

    Code:
    if(top.location !== location){
    top.location = location;
    }
    which also has many variations. What this would do is make the page in the iframe the top page.

    There might be some way of dealing with this drawback. If I think of one I'll let you know.
    - John
    ________________________

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

  2. #22
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,515
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Okay well I was fiddling with this

    HTML Code:
    <!DOCTYPE html>
    <html>
    <head>
    <?php include 'settings.php'; ?>
    <title>
    Html Editor
    </title>
    <style type="text/css">
    #window1 {
    	margin: 0;
    	background-color:<?php echo $fldrwindow1color; ?>;
    	word-wrap: break-word;
    }
    #window2 {
    	margin: 0;
    	background-color:<?php echo $fldrwindow2color; ?>;
    	word-wrap: break-word;
    }
    html, body {
    	height: 100%;
    }
    body {
    background-color:<?php echo $fldrbgcolor; ?>;
    }
    </style>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <script type="text/javascript">
    function clearwindow(){
    	var window1contents = document.getElementById('window1').innerHTML;
    	var window2contents = document.getElementById('window2').innerHTML;
    	if(window1contents == "<i>Click Here to Start Editing</i>"){
    	document.getElementById('window1').innerHTML = "&lt;html&gt;<br />&lt;head&gt;<br />&lt;/head&gt;<br />&lt;body&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;";
    	document.getElementById('window2').innerHTML = "";
    	}
    }
    function resetwindow() {
    	var window1contents = document.getElementById('window1').innerHTML;
    	var window2contents = document.getElementById('window2').innerHTML;
    	document.getElementById('window1').innerHTML = "<i>Click Here to Start Editing</i>";
    	document.getElementById('window2').innerHTML = "<I>Viewing Window</I>";
    }
    </script>
    <script type="text/javascript">
    jQuery(function($){
    	var field1 = $('#window1');
    	var update = $('#update');
    	update.click(function(){
    		if(!field1.html()){
    			alert("Please enter a value");
    			field1.focus();
    			return;
    		}
    		jQuery.ajax({
    			url: 'postedit.php',
    			type: 'post',
    			data: 'field1value=' + encodeURIComponent(field1.html()),
    			success: function(results){
    				//alert(results);
    				if(fillwindow.filled){return;}
    				$('#window2').html(results);
    			}
    		});
    	});
    });
    
    </script>
    </head>
    <body onload="this.focus()">
    	<div style="float:left; width:7.5%; height:80%;"></div>
    	<div style="float:left; width:33.3%; height:80%; border:3px darkgrey solid; overflow:auto;" id="window1" onfocus="clearwindow()" contenteditable><i>Click Here to Start Editing</i></div>
    	<div style="float:left; width:2%; height:80%;"></div>
    	<div style="float:left; width:33.3%; height:80%; border:3px darkgrey solid; overflow:auto;" id="window2"><i>Viewing Window</i></div>
    	<br style="clear: left;">
    	<div style="float:left; width:7.5%; height:10%;"></div>
    	<input type="button" value="Update" id="update" style="margin-left:0;">
    	<input type="button" value="Reset" onclick="resetwindow()">
    </body>
    </html>
    settings.php

    PHP Code:
    <?php
    $fldrbgcolor 
    "Grey";
    $fldrwindow1color "White";
    $fldrwindow2color "White";
    ?>
    I haven't changed postedit.php

    I must have stuffed something up because now when you use the enter key in
    #window1, it stuff up the window by adding a double break and moving all the #window1 text down a line. Any help???

  3. #23
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,941
    Thanks
    43
    Thanked 3,193 Times in 3,156 Posts
    Blog Entries
    12

    Default

    Add the highlighted:

    Code:
    <style type="text/css">
    #window1 {
    	margin: 0;
    	background-color:<?php echo $fldrwindow1color; ?>;
    	word-wrap: break-word;
    }
    #window1 p {
    	margin: 0;
    }
    #window2 {
    	margin: 0;
    	background-color:<?php echo $fldrwindow2color; ?>;
    	word-wrap: break-word;
    }
    html, body {
    	height: 100%;
    }
    body {
    background-color:<?php echo $fldrbgcolor; ?>;
    }
    </style>
    - John
    ________________________

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

  4. #24
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,515
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Hmmm, thanks!!!
    One more problem.
    When you press enter in field1 and put nothing on that line, it shows up as a small white filled, black bordered box.
    Any Help?

  5. #25
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,941
    Thanks
    43
    Thanked 3,193 Times in 3,156 Posts
    Blog Entries
    12

    Default

    I don't know how that's creeping in there but it's not a printable character, Unicode ffff - the highest possible value, I'm not sure what it's used for*. But we can just strip it - where you have:

    Code:
    $('#window2').html(results);
    Make that:

    Code:
    $('#window2').html(results.replace(/\uffff/g, ''));
    By the way, Firefox doesn't add it. IE may be the only one.


    *found this cryptic definition:

    Unicode FFFF is used to represent a numeric value that is guaranteed not to be a character, for uses such as the final value at the end of an index.
    - John
    ________________________

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

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
  •