Hi,

Ajax.Updater (and the underlying Element#update that it uses) are for
updating the *contents* of an element, not the *value* of an input
field. For that you want the Form.Element#setValue function[1]. Off-
the-cuff, I think your code would need to be changed like this:

function getItemInfo(){
    var vItem = $F("txtItem");  // Note 1
    var oOptions = {
        method: "get",
        parameters: {pcode: vItem}, // Note 2
        // Note 3
        onSuccess: function(response) {
            $('txtCostingUnit').setValue(response.responseText);
        }
    };
    // Note 4
    var ajax = new Ajax.Request('getcosting.php', oOptions);
}

Notes:

1. Changed to use Prototype's $F, bt your code was fine too.

2. Changed to passing parameters with an object literal instead of a
string, to let Prototype handle serializing and encoding. If you want
to use a string, change it back, but be sure to run `vItem` through
`encodeURIComponent`. Otherwise, there are lots of values for `vItem`
that will mess things up.

3. Added an onSuccess handler because we're going to...

4. ...use Ajax.Request rather than Ajax.Updater

Something along those lines, anyway.

[1] http://api.prototypejs.org/dom/form/element/setvalue/

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com


On Jul 3, 5:45 pm, ALO <iqbal....@gmail.com> wrote:
> Dear Concern,
>
> I am a fan of Prototype. Recently when I was going to use Ajax.Updater
> to update the value of a input (text) value it did not work. Please
> consider my following code and please provide me a good solution.
>
> <input name="txtItem" type="text" id="txtItem" />
> <input name="txtCostingUnit" type="text" id="txtCostingUnit" value="<?
> php if ($rn>0){echo $row[4];}?>" />
> <input name="sumbit" type="submit" value="ok" onClick="getItemInfo()">
>
> <script>
>         function getItemInfo(){
>
>            var vItem = document.getElementById("txtItem").value;
>             var oOptions = {
>                 method: "get",
>                 parameters: "pcode=" + vItem
>             };
>
>                 var ajax = new
> Ajax.Updater('txtCostingUnit','getcosting.php',oOptions);
>
>         }
> </script>
>
> If I mention any DIV ID instead of Text type Input then the script
> work fine. But my goal is to update text field value.
>
> Regards,
>
> ALO

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to