PDA

View Full Version : javascript and php help



iBrightDev
April 28th, 2007, 17:23
i was working with Colin on a script that we got working for the most part, but now i need it to do a couple other things that i think i can figure out if i can get a little help to get the next part working properly.

here is a link to the text page:
http://www.mct-hosting.com/Untitled-5.php

here is the code so far:


<span id="div3">
<span id="menuID" onclick="document.getElementById('div3').innerHTML='<input type=text value=and name=newvalue onMouseOut=document.getElementById(\'div3\').innerHTML=this. value; >'">and</span>
</span>


<?

if(isset($_GET['action'])) { // Start action check

if ($_GET['action'] == 'thanks') {
echo'Thanks';
}

}

?>


i need the javascript to call the php function on mouseout somehow. if someone can tell me how to do that, i think i can get the rest, and if not, i will let you guys/gal know. thanks in advance for help everyone.

also, the field needs to be clickable after you move the mouse away. not sure why, but it isnt clickable a second time. :S i think i can solve that isse if you can just tell me how to get it to call the function though.

krakjoe
April 29th, 2007, 11:20
<script language="javascript">

var editing = false;

function edit( )
{
if( !editing )
{
var control = document.getElementById('control');
var text = control.innerHTML;
var edit = "<input type='text' name='text' id='edited' value='"+text+"' onblur='save()'/>";
editing = true;
return control.innerHTML = edit;
}
}
function save( )
{
editing = false;
var control = document.getElementById('control');
var text = document.getElementById('edited').value;
/**
* You wanna call some ajax here to execute the php and save your stuff into the database
**/
makeRequest( 'myphp.php?data=' + encodeURI( text ), 'ajax' );
return control.innerHTML = text;
}
function makeRequest( url, element )
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
xmlhttp.open("GET", url, true );
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4) return handler( xmlhttp.responseText, element );
}
xmlhttp.send(null)
}
function handler( text, element )
{
return document.getElementById( element ).innerHTML = text;
}
</script>
<div id="cont">
<div id="control" onclick="edit()">the text to edit</div>
<div id="ajax"></div>
</div>



<?
if( $_GET['data'] )
{
echo "Your data backwards : " . strrev( urldecode( $_GET['data'] ) );
}
?>

iBrightDev
April 29th, 2007, 16:46
thanks Joe, I am working on the query part now. I will let you know how it goes. you are a life saver. thanks again