Jump to content

jug

Members
  • Posts

    64
  • Joined

  • Last visited

Everything posted by jug

  1. Hi, Im trying to create my own 'AJAX' image uploader which posts form data in a hidden iframe on the same page however I cannot get it to work without the page refreshing. The code is simple I hope I have made just a stupid error. HTML File <form id="upload_img_form" method="post" action="" onsubmit="uploadStart();" enctype="multipart/form-data"> <input type="text" name="imgname" id="imgname" value="" /> <input type="submit" name="imgbutton" id="imgbutton" value="Upload" /> <iframe id="upload_iframe" name="upload_iframe"></iframe> </form> JS File function uploadStart () { document.getElementById('img_form').target = 'upload_iframe'; document.getElementById('upload_iframe').src = 'upload.php'; $('#upload_iframe').load(function () { uploadComplete(); }); return false; } function uploadComplete () { var responseMessage = $('#upload_iframe').contents().text(); alert(responseMessage); } PHP File <?php echo $_POST['imgname']; ?> For now all I need is for the script to alert out the name of the text input without the page refreshing. From there I reckon I can sort the rest. If anyone could help me out here, itll be greatly appreciated. Thanks in advance
  2. Hi, I have quite a simple script that utilises the jquery sortable functionality. It works brilliantly in FF and chromes but fails quite spectacularly in IE8. As you will see from the code below, what Im trying to do, is to sort on two levels, horizontally and vertically. If anyone knows a workaround to make this work in IE8 it would be much appreciated. <html> <head> <title>Sortable Test</title> <script src="jquery.js" type="text/javascript"></script> <script src="jquery_ui.js" type="text/javascript"></script> <style type="text/css"> #sortable .vertical { width:600px; height:100px; border:1px solid #000; } #sortable .horizontal div { width:150px; height:80px; border:1px solid #000; float:left;} p {margin:0; padding:0;} </style> <script type="text/javascript"> $(function() { $("#sortable").sortable(); $("#sortable .horizontal").sortable(); }); </script> </head> <body> <div id="sortable"> <div class="vertical"> <p>here</p> <div class="horizontal"> <div><p>here</p></div> <div><p>here</p></div> <div><p>here</p></div> </div> </div> <div class="vertical"> <p>here</p> <div class="horizontal"> <div><p>here</p></div> <div><p>here</p></div> </div> </div> </div> </body> </html> Thanks in advance jug
  3. Hi, Depending how big your sub category results set is you can do it one of two ways. The first is to echo out the database subcategories into JS arrays when the page is loaded. This doesnt really work well when you have loads of data as everything is loaded upfront but if you have a small set of subcategories it is a consideration and means that on any user interaction the response is pretty much instant. The second way is to use AJAX. If youre not familiar with this technique look here -> http://www.w3schools.com/ajax/default.asp or alternatively if you know jquery, that allows you to use AJAX very easily. AJAX allows you to call server side scripts without a page refresh. This is obviously better as only the data youre after will be loaded, but requires a bit more patience and knowledge (worth knowing though). An AJAX response could be in a couple of formats, but if you choose XML, that would allow you to populate the second select very easily indeed. Hope this helps. jug
  4. Hi, You would need to put the on click function call on every radio button. So.. <input type=\"radio\" class=\"radio_button\" name=\"destination\" value=\"1\" onclick=\"enableElement();\">Spain <input type=\"radio\" class=\"radio_button\" name=\"destination\" value=\"2\" onclick=\"enableElement();\">France <input type=\"radio\" class=\"radio_button\" name=\"destination\" value=\"3\" onclick=\"enableElement();\">Other function enableElement () { var radioValue = ''; var selection = document.getElementsByName('destination'); for (i=0; i<selection.length; i++) { if (selection[i].checked) { radioValue = selection[i].value; break; } } if (radioValue == 'other') { //enable text box } else { //disable text box } } I havent tested this code but hopefully it will help you on your way. jug
  5. Havent tried it myself, but this link may help. http://stackoverflow.com/questions/139118/javascript-iframe-innerhtml jug
  6. You were almost there. Obviously change back the links to youre local jquery files. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jQuery UI Test Page</title> <script src="jquery.js" type="text/javascript"></script> <script src="jquery_ui.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $('#fruit_sort').sortable(); }); </script> </head> <body> <ul id="fruit_sort"> <li id="fruit_1">Apple</li> <li id="fruit_2">Orange</li> <li id="fruit_3">Pear</li> </ul> </body> </html> reqards jug
  7. thanks for your reply. I did try that too but had no luck. In the end I settled for using eval. Not ideal but does the job. jug
  8. Hi, Is there any way to pass dynamic arguments to array_multisort. Below is my idea of what the code should look like. First it has the data then its builds an array of array indexes with the sort direction. This array is then passed to the array_multisort function with the original data. $data[] = array([0] => 67, [1] => 2, [3]' => 2001);$data[] = array([0] => 86, [1] => 4, [3]' => 2002);$data[] = array([0] => 98, [1] => 5, [3]' => 2002);$data[] = array([0] => 86, [1] => 6, [3]' => 2003);$data[] = array([0] => 67, [1] => 1, [3]' => 2004);$arg = array(1 => SORT_ASC, 3 => SORT_DESC);array_multisort($arg, $data); I have got this working with hardcoded values, for example... array_multisort($sort1, SORT_ASC, $sort3, SORT_DESC, $data); but in my code instead of just 2 sorts there could be 'x' amounts. I hope ive made this clear. Any response would be much appreciated. Thanks in advance.
  9. Hi, Im after a jQuery plugin that can resize table columns like http://www.ita.es/jquery/jquery.grid.columnSizing.htm and also resort sort table columns like http://akottr.de/dragtable/. Also what I want is for the markup to not be generated by the plugin so... <table id="mytable"> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> </table> rather than something like <div id="mytable></div> which more extensive plugins like jqgrid do. If anyone could enlighten me on such a plugin or alternatively show me how to use the two i have already mentioned in conjunction with each other, that would be great. Thanks in advance
  10. I think what youre after is the onkeyup event (http://www.w3schools.com/jsref/event_onkeyup.asp). Place it on the text input to perform a check on the form info. eg. if(...code here...){ document.getElementById('submitbuttonidhere').disabled = false; } Hope this helps
  11. I know people dislike bumping but has no one got any idea. Any response would be appreciated. Thanks
  12. yeh set a timeout out on 'body onload' for 60 mins in seconds with a statement that disables the button. The button would have to be set with an id. so something like (though untested) .... <html> <head> <script type="text/javascript"> function startTimer(){ var t = setTimeout("document.getElementById('formbutton').disable=true;", 360000); } </script> </head> <body onload="startTimer();"> <form> <input type="submit" id="formbutton" name="formbutton" value="Submit" /> </form> </body> </html> hope this helps
  13. Hi, If youre just submitting the form and wanting the form input to be displayed below without a page refresh then MySQL or any server side language doesnt need to be used. If on the other hand you do want the services of a back end database then AJAX is the answer. For a resource then w3c schools (http://www.w3schools.com/ajax/default.asp) is the best place to start. Hope this helps jug
  14. nearly <script type="text/javascript"> var url = document.location.href; window.location = 'http://localhost/blocked.php?url=' + url; </script>
  15. Not quite sure what your are trying to achieve generally, but yeh its possible. Dont think a textbox is the best input element for this but if you must use it, then each url needs to be separated by a delimiting character, like a comma and then when the button is submitted, split the textbox string using the delimiter into an array. Now with the array, where each item should be a different url of an image, loop through these items and display them on the page. I know code examples may help more here but this hopefully should give you a start. Best jug
  16. Hi, Basically what Im trying to do is pass a function name as a string to a function where the code checks it existence before calling the function with parameters. Below is a very simplified version of the code that will hopefully show what Im trying to achieve. It is not working code yet but you can get the gist. function process(){ check('function1'); } function check(functionName){ var output = 'test'; if(!(window[functionName])){ alert('no'); }else{ window[functionName](output); } } function function1(output){ alert(output); } Any response will be much appreciated Thanks in advance jug
  17. you want something like <html> <head> <script type="text/javascript"> function startTimer(){ var t = setTimeout("alert('5 seconds!')",5000); } </script> </head> <body onload="startTimer();"> //html here </body> </html> though edit it for 60 mins hope this helps
  18. Thanks for that. I was sure it meant something. Anyone know (out of curiousity) why PHP doesnt just say 0.000029...s rather than 2.9999999999974E-5s? jug
  19. Hi, Looking through previous posts there is one thread that I found that covers the issue but the solution did not work for me. http://www.phpfreaks.com/forums/index.php/topic,214582.msg980170.html#msg980170 What I am trying to do is use microtime to see how long a script takes to execute. Im expecting a figure that is below one, for example 0.034532. But what I am getting is a figure similar to 2.9999999999974E-5. What does this mean? And how can I solve it? The code I am using is below and is very simple and almost identical to one example found in the documentation on php.net. $time_start = microtime(true); //script here $time_end = microtime(true); $time_taken = $time_end - $time_start; echo ' Time taken: ' . $time_taken; Thanks in advance jug
  20. Hi, AJAX could be used here but depending on your needs you may only need something like lightbox (http://www.huddletogether.com/projects/lightbox2/) or fancybox (http://fancybox.net/). Take a look at the link below. http://www.rob-passmore.co.uk/gallery/portrait/ This is a site I developed and includes a gallery very similar to your description. No AJAX is involved here and it is just the use of the brilliant fancybox. Hope this helps. jug
  21. Hi, You would probably have to use an iFrame and possible an onclick event on the file input or the submit button. The image would have to be uploaded to be displayed. http://www.atwebresults.com/php_ajax_image_upload/ The link above is a good example of this technique. Take a look. Hope this helps jug
  22. Hi, You need to be more specific in your original post. Im guessing youre obviously having problems. What are these problems? What errors are you getting? Where is the error occuring? These are all questions that if you answer in the next reply you may get a solution. jug
  23. Hi, I am experimenting with the BBC web API and have come across certain problems. It seems the status code returned from the server response is 0 and also the xml response is null. Im not totally new to Ajax development but I cant seem to see where the problem lies. The section of code is below. function channelsList(){ req = new XMLHttpRequest(); req.open("GET", 'http://www0.rdthdo.bbc.co.uk/cgi-perl/api/query.pl?method=bbc.channel.list&format=simple', true); req.onreadystatechange = channelsListResponse; req.send(null); } function channelsListResponse(){ alert(req.readyState + '-' + req.status + '-' + req.statusText); if(req.readyState == 4 && req.status == 200){ var channelsList = req.responseXML.getElementsByTagName('channel'); alert(channelsList); } } Any help would be appreciated. The prototype application can be found at the following URL. http://dev.bw-design.co.uk/sites/bbc/ Thanks in advance. Aaron B
  24. Hi, I would achieve this a different way. I would use the 'responseText' method of the xmlHttpRequest and generate the HTML output in the PHP/ASP script file. From here, using the 'repsonseText' method in the JavaScript file, you can retrieve the generated HTML code from the script and use DOM to add to the innerHTML of any object. Hope this helps jug
  25. Hi, I have been developing this script for a few days with its objective to make ajax requests scripts a lot easier to write each time. The errors Im getting are mainly server readystate and status errors (not being the correct code). Also I am fairly new to making custom JavaScript objects. If anyone could quickly look through the script and point anything out itll be much appreciated. Thanks in advance jug calling the function function process(){ var XHR = new ajaxRequest(scriptPath, 'XML', response); XHR.doPost(params); } return false; } function response(xmlResponse){ //stuff here } custom ajax object function ajaxRequest(url, responseType, callback){ var req = init(); req.onreadystatechange = processRequest; var errorText = 'no errors'; function init(){ if(window.XMLHttpRequest){ return new XMLHttpRequest(); }else{ errorText = 'Your browser does not support the XMLHttpRequest object.'; } } function processRequest(){ if(req.readyState != 4){ errorText = 'Server ready state is not 4.'; }else{ if(req.status != 200){ errorText = 'Server status is not 200.'; }else{ switch (responseType){ case 'Text': callback(req.responseText); break; case 'XML': callback(req.responseXML); break; default: errorText = 'Incorrect server response type.'; } } } } this.doPost = function(params){ if(req.readyState == 0 || req.readyState == 4){ try{ req.open("POST", url, true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send(params); }catch(e){ errorText = 'XMLHttpRequest POST url not found.'; } }else{ setTimeout('doPost(params)', 1000); } } this.doGet = function(){ if(req.readyState == 0 || req.readyState == 4){ try{ req.open("GET", url, true); req.send(null); }catch(e){ errorText = 'XMLHttpRequest GET url not found.'; } }else{ setTimeout('doGet()', 1000); } } this.getErrorText = function(){ return errorText; } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.