Jump to content

[SOLVED] Look up text from input field and insert returned values into other input fields


cyfer

Recommended Posts

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.

Link to comment
Share on other sites

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'];
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.