AJAX for extra input fields

Posted on 2007-10-03
Last Modified: 2012-08-14
I have a form that asks users to fill in the quantity of an item they have sold. The form has about 20 products, each with a text input field to enter the quantity. I now find that I also need to capture each item's serial number.

I would like to design the form so that if the user enters 4 as the quanity purchased, four text input fields appear below the original, to accept the serial number information.

I need the AJAX to show the appropriate input fields for the serial numbers and to allow server side verification of the serial numbers as they are entered.

My current input variables are arrays: e.g. <input type='text' name='prod[PC900]' value='' size='6'>

I would prefer the serial number be a compound array. e.g. prod_serial[PC900][1], prod_serial[PC900][2].

I am already using some AJAX on the page using Rafael Dohms brilliant autocomplete script for the company field, and I have used some other AJAX code on my site (although not on this page), but they have been modifiations of published scripts. I am not a Java/AJAX guru myself.  

I am using PHP for the server side.

I really appreciate your help.

Question by:birwin
    LVL 48

    Accepted Solution

    Using it shpould be easy to accomplish:

    <input type=text' name='prod[PC900]' value='' size='6' onchange="xajax_addSerials('PC900', this.value, xajax.getFormValues('formId'));"><div id="PC900Serials"><div>

    function addSerials($prod, $num, $formdata)
        $result = '';
        for ($i= 0; $i <= $num; ++$i) {
           $result .= '<input name="prod_serial['.$prod.']['.$i.']">';
        $objResponse = new xajaxResponse();
        $objResponse->assign($prod . "Serials","innerHTML", $result);
        return $objResponse;

    Read the tutorial/demos for integration xajax into your php-scripts
    LVL 6

    Author Comment

    I tried to set this up, but I am having trouble getting xajax to work. I have installed it, and I can get the examples to work and as far as I can determine, I am setting it up according to the examples, but I keep getting an error "Fatal error: Call to undefined method xajax::processRequests()"

    Can you give me the full xajax code to make this work?

    Also my site is templaed, so I need to be able to load the variable $display with any displayed output or $head for any code that appears in the head of the document.


    I will gladly award more points, or if you are available freelance, I can hire you to complete the code for me.
    LVL 6

    Author Comment

    Dear hernst42:

    As luck would have it, my clent changed their mind and no longer want this option.

    I'll still try hacking through xajax, since it seems to be a very useful program.

    Thank you for your solution.

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Suggested Solutions

          Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
    Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    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)

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now