Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

prototype and populate form fields

Posted on 2006-06-22
8
Medium Priority
?
352 Views
Last Modified: 2008-01-09
I need some help with what I thought was going to be simple but turned out to be less then simple, alright for some this could be done in their sleep.

I need to update several form fields using prototype library.  I have attempted once but oddly enough when I made the request it would just load the page that I was querying.

So anyway after the person exits a certain field I need it to take the input from that field and query a page and then return the results and populate the fields.

js..
function ajaxGetFields()
      {
            var custNum = $F('custnum');
            var url = 'http://localhost/cs.php';
            var pars = 'cn=' + custNum;
            
            var myAjax = new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: showResponse });

      }

      function showResponse(originalRequest)
      {
            //put returned XML in the textarea
            $('result').value = originalRequest.responseText;
      }

...

<input type="text" id="custnum" name="_custnum" tabindex="1" value="" onchange="ajaxGetFields()">
leaves this field

<input type="text" id="bill_to_name" name="bill_to_name" tabindex="1" value="">
<input type="text" id="bill_to_add1" name="bill_to_add1" tabindex="1" value="">
<input type="text" id="bill_to_add2" name="bill_to_add2" tabindex="1" value="">
...
0
Comment
Question by:iceman19330
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 18

Expert Comment

by:Morcalavin
ID: 16960503
$('result').value

What element is being populated here?  You will need to parse the data you are receiving and put it in your form fields.  How is the data being returned(the format)?
0
 

Author Comment

by:iceman19330
ID: 16960604
right now its an echo statement from a php page, but I was thinking of doing xml return.  No elements are being updated.
0
 
LVL 18

Accepted Solution

by:
Morcalavin earned 2000 total points
ID: 16960648
$('result').value is being updated:
$('result').value = originalRequest.responseText;

On one of my pages on our intranet, I send out a bunch of database records and use @DELIM@ as a field delimiter, so my response is:
record1@DELIM@record2@DELIM@ etc...
Then I use javascript to split the string into an array:
myArray = responseText.Split('@DELIM@');
$F('mytextfield1') = myArray[0];
$F('mytextfield2') = myArray[1];

etc etc etc.

It all depends on how complicated your return results are.  It should be a simple format as possible.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:iceman19330
ID: 16960689
I can do it however I want :), XML I thought was logical just not sure how to parse it on the return.  I will try the delimiter approach.
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 16960728
XML is great, but I found in many cases, I was returning hundreds of characters, when the only part I wanted was a small section of it.  It's also more troublesome to parse, depending on what info it contains.
0
 

Author Comment

by:iceman19330
ID: 16961081
function ajaxGetFields()
      {
            var custNum = $F('custnum');
            var url = 'http://localhost/cn.php';
            var pars = 'cn=' + custNum;
            alert("customer number: " + custNum);
            var myAjax = new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: showResponse });

      }

      function showResponse(originalRequest)
      {
            //put returned XML in the textarea
            alert("response1: " + originalRequest.responseText);
            $('result').value = originalRequest.responseText;
            myArray = originalRequest.responseText.Split('|');
            alert("response1: " + myArray);
            $F('bill_to_name') = myArray[0];
            $F('bill_to_add1') = myArray[1];
            $F('bill_to_add2') = myArray[2];
            $F('bill_to_city') = myArray[3];
            $F('bill_to_state') = myArray[4];
            $F('bill_to_zip') = myArray[5];
      }

I can see the response back from here alert("response1: " + originalRequest.responseText) after that point its gone, the next alert doesnt even go off.
0
 

Author Comment

by:iceman19330
ID: 16961364
Okay I got the split to work Split is case sensitive, now I guess I have to figure out why its not going into the fields.
0
 

Author Comment

by:iceman19330
ID: 16961484
Got it

needed to change the $F('bill_to_name') = myArray[0]; to $('bill_to_name').value = myArray[0];

:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question