943,172 Members | Top Members by Rank

Ad:
Sep 2nd, 2010
0

Autofilling a text field based on prior input

Expand Post »
I've only just started playing with AJAX, as part of a project I'm dealing with at work.

The specific piece I'm stuck on at the moment is this:

I have a form with a lot of fields, two of which are subnet (a drop box populated from a database, via PHP) and IP address (a text input box). When the user selects a subnet, the value is sent to a PHP script that queries the DB and returns the next unused IP address. If all I wanted was to display that in a div next to the IP input box, I'd be set -- that works fine.

Unfortunately, I can't for the life of me figure out how to get the returned data into a text input box, which is what I actually want.

I know that document.getElementById("div_id").innerHTML=request.responseText; will display the text in a div in my sample code. I found a post somewhere that implied that frm.getElementById("input_id").value = request.responseText; would do the job for a text input, but it doesn't, at least in any of the browsers I've tested.

If anyone could point me in the right direction, I'd greatly appreciate it.

Thanks in advance,
Alex
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
amckenzie4 is offline Offline
2 posts
since Sep 2010
Sep 2nd, 2010
0
Re: Autofilling a text field based on prior input
Wouldn't you know it... after searching for days, I post here, and half an hour later I find a solution. In brief, here's how it works, assuming that the form has an id of "add_form" and the field is named "ip" and also has an ID of "ip":

[code]document.getElementById('add_form').elements.namedItem('ip').value = request.responseText;[code]

I'm not sure why I never got it to work with just "document.getElementById('ip').value = request.responseText", but I'll assume I either had a typo or misunderstood something.

Hopefully this will help the next person who's looking for this solution!

-Alex

P.S. I found the solution at http://userscripts.org/topics/1199
Reputation Points: 10
Solved Threads: 0
Newbie Poster
amckenzie4 is offline Offline
2 posts
since Sep 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Could I download the html text from other website using AJAX?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: How has Daniweb made it's pop-up?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC