[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to read a form field from a website

Posted on 2003-11-09
6
Medium Priority
?
220 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
  • 3
4 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 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