Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

TWebbrowser - Modify value of Combobox in a web form

Posted on 2006-05-29
5
Medium Priority
?
483 Views
Last Modified: 2011-09-20
Hi there,

I have source code for filling out a website form (ie the text area's etc) however how can I mofiy the value of the combo box?

Lets say I have a drop list of 5 items, how can I programmicly set one of them as being displayed in the Twebbrowser? =)

Thanks
0
Comment
Question by:wildzero
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16788075
Hi,

you can do it using Javascript! Create a javascript that does the selection.

e.g.

var
  s : TStringList;
begin
  s := TStringList.Create;
  s.Add('javascript:function myselect() {');
  s.Add('var cb=document.getElementById(''Test'');');
  s.Add('cb.selectedIndex=2;'); // here you select the index
  s.Add('}; myselect();');
  WebBrowser1.Navigate(s.Text);
  s.Free;
end;
0
 
LVL 10

Author Comment

by:wildzero
ID: 16788949
atul_parmar
so with your example, I first load up the website with the from
then run your above code so on that page that is already loaded the drop list index changes to the the specified selectedIndex.

is the selected index the count of items 0 --> end or is it the value of the item? or the displayed text

exmaple

<option value"something">One thing</option>
<option value"another">More things</option>
<option value"more">Another things</option>

with your code would that set it to
<option value"more">Another things</option>

or would it not match any?

Thanks
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16789003
It would set it to <option value"more">Another things</option>

the selectedIndex property is the index of the selected item and first item will have the index of 0 (zero) and last will have the count-1.

0
 
LVL 10

Author Comment

by:wildzero
ID: 16792980
k
What happens if the position of the item was unknown?
What would happen if I wanted to select
<option value"another">More things</option> but didn't know it's position in the list?
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 1000 total points
ID: 16796330
Well, Here is modified version of the same javascript what will search the value and set its index. All you have to do is to provide the correct value.
 
var
  s : TStringList;
  TextToFind : string;
begin
  TextToFind := 'another';
  s := TStringList.Create;
  s.Add('javascript:function myselect() {');
  s.Add('var cb=document.getElementById(''Test'');');
  s.Add('var i=0;');
  s.Add('while (i<cb.length) {');
  s.Add('if (cb.options[i].value==''' + TextToFind + ''') {cb.selectedIndex=i;break;}');
  s.Add('i++;');
  s.Add('}'); // end while
  s.Add('}; myselect();');
  WebBrowser1.Navigate(s.Text);
  s.Free;
end;


Atul
0

Featured Post

Industry Leaders: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month20 days, 21 hours left to enroll

810 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