Solved

How to read a form field from a website

Posted on 2003-11-09
6
204 Views
Last Modified: 2010-04-05
Dear all,

How can I read a form field value (MyField) from a website (http://www.mysite.com/mypage.htm)?
I'm using Delphi 7 with Indy.

Thanks, Abraham
0
Comment
Question by:abraham_ll
[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
  • 3
6 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9737236
If you just load the source, it won't have a value. Please explain further or give a better example.
0
 

Author Comment

by:abraham_ll
ID: 9738036
Thank you for your reply EddieShipman.

This is a form field which displays the users IP number.  So on load it has a value. Here is the code:

<script language="javascript">
  var ip = '<!--#echo var="REMOTE_ADDR"-->'
  function ipval() {document.myform.ipaddr.value=ip;}
  window.onload=ipval
</script>
<form method="post" action="" name="myform">
  <input type="text" name="ipaddr" readonly>
</form>
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9738951
very easy. I will post a solution in a couple of hours.
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 125 total points
ID: 10499068
So sorry it has taken me so long to do this...

procedure TForm1.ParseURL(AURL: String);
Var
  IDoc:IHTMLDocument2;
  Strm:TSTringStream;
  v:Variant;
  i       : Integer;
  vMeta   : IHTMLMetaElement;
  vAll    : IHTMLElementCollection;
  vElement: IHTMLElement;
begin
  Memo1.Clear;
  Strm:=TSTringStream.create('');
  Idhttp1.Get(AURL,strm);
  Idoc:=CreateComObject(Class_HTMLDocument) as IHTMLDocument2;
  IDoc.designMode:='on';
  while IDoc.readyState<>'complete' do
    Application.ProcessMessages;
  v:=VarArrayCreate([0,0],VarVariant);
  v[0]:= Strm.datastring;
  IDoc.write(PSafeArray(System.TVarData(v).VArray));
  IDoc.designMode:='off';
  while IDoc.readyState<>'complete' do
    Application.ProcessMessages;

  vAll := iDoc.all.tags('INPUT');
  for i:=0 to vAll.Length-1 do
  begin
   vElement:= vAll.item(i, varEmpty);
 
   if (vElement.getAttribute('Name', 0) = 'ipaddr') then
   begin
     Result := vElement.getAttribute('Value', 0);
   end;
  end;
  IDoc := nil;
  Strm.Free;
end;
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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