cyfer Posted November 23, 2008 Share Posted November 23, 2008 Okay so i've been doing some investigation on google and haven't been able to come up with anything that was doing what i want or close so i could modify it (even that.. please note i'm no good at javascript) What i need is as follows. Page 1: Here i have a form in which i have several input fields. Next to one of these should be a button the user can press. This should do one of two things (whatever you can manage). One solution - take the text put into the field and open a popup window where the text will be available via ex get or post so i can fetch it in my php script. This php script returns some values which needs to go back to page 1 and be put into the other fields. Another solution would be to not open any popup window but do the entire process in the bacground loading the php script i've got. But this sounds pretty advanced?? Thanks in advance. I appreciate your help. Quote Link to comment Share on other sites More sharing options...
php_tom Posted November 23, 2008 Share Posted November 23, 2008 your second solution is possible -- with ajax. try this: HTML: <input type='text' id='field1' /> <input type='button' value='go' onclick='ajaxpage("/path/to/php/script.php?field1="+document.getElementById('field1').value ,"results")' /> <div id='results'></div> JavaScript: var root = 'http://www.yoursite.com'; function ajaxpage(url, containerid){ var page_request = false; document.getElementById(containerid).innerHTML = "Loading..."; if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest(); else if (window.ActiveXObject){ // if IE try { page_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){} } } else return false; page_request.onreadystatechange=function(){ loadpage(page_request, containerid); } page_request.open('GET', root+url, true); page_request.send(null); } function loadpage(page_request, containerid){ if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) document.getElementById(containerid).innerHTML=page_request.responseText; } PHP: <?php // Do something with the data, then print some output. echo $_GET['field1']; ?> Quote Link to comment Share on other sites More sharing options...
cyfer Posted November 23, 2008 Author Share Posted November 23, 2008 Thanks that works well. Quote Link to comment 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.