madspof Posted November 15, 2009 Share Posted November 15, 2009 Hi all i have decided to have a play with ajax but as i have no javascript knoweldge i am having a few problems i have got the code below to work when it is sending the result variable from the upload.php back to the form but when i tried to send another variable containing a string, the php script will upload the file but the java script in the form will not show uploaded : Here is the link to the upload www.desfun.co.nr/dolphins/upload/ and the code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Max's AJAX File Uploader</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"> <!-- function startUpload(){ document.getElementById('f1_upload_process').style.visibility = 'visible'; document.getElementById('f1_upload_form').style.visibility = 'hidden'; return true; } function stopUpload(success,url){ var result = ''; var url = ""; if (success == 1){ result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>'; } else { result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>'; } document.getElementById('f1_upload_process').style.visibility = 'hidden'; document.getElementById('f1_upload_form').innerHTML = result + url + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>'; document.getElementById('f1_upload_form').style.visibility = 'visible'; return true; } //--> </script> </head> <body> <div id="container"> <div id="header"><div id="header_left"></div> <div id="header_main">Max's AJAX File Uploader</div><div id="header_right"></div></div> <div id="content"> <form action="upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" > <p id="f1_upload_process">Loading...<br/><img src="loader.gif" /><br/></p> <p id="f1_upload_form" align="center"><br/> <label>File: <input name="myfile" type="file" size="30" /><BR /> </label> <label><input name="sd" type="text" id="sd" value="lol" /></label><BR /> <label> <input type="submit" name="submitBtn" class="sbtn" value="Upload" /> </label> </p> <iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe> </form> </div> <div id="footer"><a href="http://www.ajaxf1.com" target="_blank">Powered by AJAX F1</a></div> </div> </body> And the php <?php include("../connect.php"); $id = "3"; $BFA = "213"; $BFAl = "F"; $BREED = $_POST['sd']; $HEIGHT = "232"; $NAME = "hah"; $URL = "ollol"; // Edit upload location here $destination_path = 'C:\Deskfun\Dolphins\asa\\'; mysql_query("INSERT INTO dogs VALUES ('$id','$BFA','$BFAl','$BREED','$HEIGHT','$NAME','$URL')"); $result = 0; //echo $to; $target_path = $destination_path . basename( $_FILES['myfile']['name']); if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) { $result = 1; } sleep(1); ?> <script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo "$result,$URL"; ?>);</script> can anyone see why?? Thanks before hand :) Quote Link to comment https://forums.phpfreaks.com/topic/181627-form-will-not-work/ Share on other sites More sharing options...
madspof Posted November 15, 2009 Author Share Posted November 15, 2009 Ok i have been playing and if i pass text through the varaibles into the stopUpload function it will not work it just stops for some reason but if they are numerical values it does is there some kind of syntax i am missing ? Quote Link to comment https://forums.phpfreaks.com/topic/181627-form-will-not-work/#findComment-958085 Share on other sites More sharing options...
madspof Posted November 16, 2009 Author Share Posted November 16, 2009 Ok ive fixed that problem i had to put the php variables into javascript ones before i entered it into the function btw i now have a problem with hidding a table i am changing the style.display to block and none trying to hide the form at certain point but cannot get it to work properly for the form with a table in does anyone know why this might be ? Quote Link to comment https://forums.phpfreaks.com/topic/181627-form-will-not-work/#findComment-958424 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.