|
Posted by Harlan Messinger on May 27, 2008, 4:16 pm
Please log in for more thread options David Tay wrote:
[top-posting corrected]
> On May 27, 7:53 am, Harlan Messinger
>> David Tay wrote:
>>> Is there a text field tag with a value parameter that I can refer to
>>> with Javascript besides the input tag?
>>> What I have been doing is using Ajax and PHP to pull data out of a
>>> database. Then with Javascript I have been filling the value of an
>>> input text field with with that data. The input text field has its
>>> border styled off so it looks just like text.
>>> Is there a cleaner way of doing this?
>> It's tricky to respond to a person who says what he is doing rather than
>> stating what he is trying to accomplish--*why* he is doing it. I'm
>> inferring that (a) you want the data to appear as text on the screen and
>> (b) you also want it to be submitted along with other data from a form.
>>
>> The proper approach is (a) to display it as ordinary text where you want
>> it to appear as ordinary text and (b) also to include a *hidden* input
>> element on the form with the required data as its value.
> What I was trying to do was to display rows from a database using
> Ajax. In order to do that I had to create an input field whose value I
> would assign with Javascript. For example:
>
> First name: <input name="firstName" value="" style="border-width:
> 0px"><br/>
> Last name: <input name="lastName" value="" style="border-width:0px">
>
> Now in Javascript, I would do the following:
>
> if (xmlHttp.readyState==4){
> var names = new Array();
> names = xmlHttp.responseText.split("&");
> var firstName = document.getElementsByName("firstName");
> var lastName = document.getElementsByName("lastName");
> firstName[0].value=names[0];
> lastName[0].value=names[1];
> }
>
> Do you understand now?
>
No, you haven't bothered to explain why these items need *both* (a) to
look like text and yet (b) function is input fields. The code you have
seems to accomplish what it is you want superficially, yet you asked
your question, so I'm trying to figure out what your underlying goal is
that might lead one to look for a different approach.
|