Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Populate a dropdown list
#1
I was trying to do some auto-population of form fields, but ran into a problem with the population of a dropdown list. Perhaps it could be clicked via one of the methods you offer and then the appropriate option could be chosen? Anyway, this was a problem I was trying to solve.
Reply
#2
Hello,

Thank you for your question.
The VB6 Fill Form demo has some code that does what you're asking.
Let me copy & paste the relevant details.

Following is the content of the "Change Html" button Click method:
Code:
Private Sub ChangeHtmlButton_Click()   Dim Html As String ' change the html of an input textbox into a select (drop down)   InfoText.Text = "Changing the login name input textbox into a dropdown"   Html = "<select name=""username"">" & vbCrLf   Html = Html & "  <option value=""Sylvia"">Sylvia</option>" & vbCrLf   Html = Html & "  <option value=""Johnson"">Johnson</option>" & vbCrLf   Html = Html & "  <option value=""Romeo"">Romeo</option>" & vbCrLf   Html = Html & "  <option value=""Mario"">Mario</option>" & vbCrLf   Html = Html & "  <option value=""Mr. Smith"">Mr. Smith</option>" & vbCrLf   Html = Html & "  <option value=""Liza"">Liza</option>" & vbCrLf   Html = Html & "</select>" & vbCrLf   Document.SetElementOuterHtmlByName "username", Html End Sub

This changes the existing html text control into a drop down.
Clicking on that button will show you that it actually replaces that text control with the html of a dropdown and it shows the list as below:
   

If you then click on the "Fill Form" button, it will select the "Mr Smith" option from the list.

The code of the Fill Form button click event looks like this:
Code:
Private Sub FillFormButton_Click()   Document.ElementValueByName("username") = "Mr. Smith"   Document.ElementValueByName("password") = "supersecret"   Document.ElementValueByName("your-none-existing-input") = "smith@example.com"   Document.SetInputCheckboxByName "remember", True   InfoText.Text = "Next Click the Read Form button." End Sub

Hope this helps,
Wil

PS: I will be moving this thread to the AntView section in a bit.

Edit: See this help page, for a walk-through of this particular example: VB6 - Fill Form Example
Reply
#3
(Today, 10:51:15)wila Wrote: Hello,

Thank you for your question.
The VB6 Fill Form demo has some code that does what you're asking.
Let me copy & paste the relevant details.

Following is the content of the "Change Html" button Click method:
Code:
Private Sub ChangeHtmlButton_Click()   Dim Html As String ' change the html of an input textbox into a select (drop down)   InfoText.Text = "Changing the login name input textbox into a dropdown"   Html = "<select name=""username"">" & vbCrLf   Html = Html & "  <option value=""Sylvia"">Sylvia</option>" & vbCrLf   Html = Html & "  <option value=""Johnson"">Johnson</option>" & vbCrLf   Html = Html & "  <option value=""Romeo"">Romeo</option>" & vbCrLf   Html = Html & "  <option value=""Mario"">Mario</option>" & vbCrLf   Html = Html & "  <option value=""Mr. Smith"">Mr. Smith</option>" & vbCrLf   Html = Html & "  <option value=""Liza"">Liza</option>" & vbCrLf   Html = Html & "</select>" & vbCrLf   Document.SetElementOuterHtmlByName "username", Html End Sub

This changes the existing html text control into a drop down.
Clicking on that button will show you that it actually replaces that text control with the html of a dropdown and it shows the list as below:


If you then click on the "Fill Form" button, it will select the "Mr Smith" option from the list.

The code of the Fill Form button click event looks like this:
Code:
Private Sub FillFormButton_Click()   Document.ElementValueByName("username") = "Mr. Smith"   Document.ElementValueByName("password") = "supersecret"   Document.ElementValueByName("your-none-existing-input") = "smith@example.com"   Document.SetInputCheckboxByName "remember", True   InfoText.Text = "Next Click the Read Form button." End Sub

Hope this helps,
Wil

PS: I will be moving this thread to the AntView section in a bit.

Edit: See this help page, for a walk-through of this particular example: VB6 - Fill Form Example

That's not working. The HTML snippet is:

Code:
<form id="DSForm" novalidate="novalidate"> <div class="panel-message"></div>   <div class="form-group">   <label for="MakeID" class="required" aria-required="true">Make</label>     <span class="pull-right"><a href="#" class="btn-link" id="btn-no-make">Don't See Your Make or Model?</a></span>     <div class="clearfix"></div>     <select id="MakeID" name="MakeID" data-placeholder="Make" class="form-control select2-hidden-accessible" aria-required="true" tabindex="-1" aria-hidden="true">     <option></option>       <option value="1">Acura</option><option value="391">Advance Mixer</option><option value="383">Alexander Dennis</option><option value="2">Alfa Romeo</option><option value="3">AM General</option><option value="4">AMC</option><option value="339">American LaFrance</option><option value="285">Amphicar</option><option value="5">Aston Martin</option><option value="816">Auburn</option><option value="6">Audi</option><option value="216">Austin</option><option value="164">Austin-Healey</option><option value="340">Autocar</option><option value="393">Battle Motors</option><option value="341">BCI</option><option value="7">Bentley</option><option value="342">Bering</option><option value="174">Blue Bird</option><option value="8">BMW</option><option value="863">Bollinger Motors</option><option value="390">BrightDrop</option><option value="9">Bugatti</option><option value="10">Buick</option><option value="384">BYD</option><option value="11">Cadillac</option><option value="878">Canoo</option><option value="343">Capacity</option><option value="914">Caterham</option><option value="190">Caterpillar</option><option value="855">Cenntro</option><option value="12">Chevrolet</option><option value="13">Chrysler</option><option value="824">Citroen</option><option value="344">Crane Carrier</option><option value="14">Daewoo</option><option value="15">Daihatsu</option><option value="16">Datsun</option><option value="282">De Tomaso</option><option value="229">DeLorean</option><option value="176">Desoto</option><option value="17">Dodge</option><option value="18">Eagle</option><option value="346">Eagle Motor Coach</option><option value="228">Edsel</option><option value="345">E-ONE</option><option value="347">Federal Motors</option><option value="19">Ferrari</option><option value="20">FIAT</option><option value="21">Fisker</option><option value="348">Flxible</option><option value="22">Ford</option><option value="83">Freightliner</option><option value="288">Genesis</option><option value="23">GEO</option><option value="349">Gillig</option><option value="24">GMC</option><option value="350">Grumman</option><option value="920">Harbinger Motors</option><option value="351">Hendrickson</option><option value="125">Hino</option><option value="25">Honda</option><option value="26">HUMMER</option><option value="27">Hyundai</option><option value="352">IC Bus</option><option value="395">Ineos</option><option value="28">Infiniti</option><option value="81">International</option><option value="353">Irisbus</option><option value="29">Isuzu</option><option value="354">Iveco</option><option value="30">Jaguar</option><option value="31">Jeep</option><option value="830">Jensen</option><option value="98">John Deere</option><option value="198">Kaiser</option><option value="355">Kalmar</option><option value="296">Karma</option><option value="394">Karsan</option><option value="104">Kenworth</option><option value="32">Kia</option><option value="33">Lamborghini</option><option value="286">Lancia</option><option value="34">Land Rover</option><option value="35">Lexus</option><option value="36">Lincoln</option><option value="37">Lotus</option><option value="388">Lucid</option><option value="138">Mack</option><option value="917">Magirus Deutz</option><option value="385">Magnum Manufacturing</option><option value="356">Marmon</option><option value="38">Maserati</option><option value="39">Maybach</option><option value="40">Mazda</option><option value="41">McLaren</option><option value="42">Mercedes-Benz</option><option value="43">Mercury</option><option value="44">Merkur</option><option value="87">MG</option><option value="45">MINI</option><option value="46">Mitsubishi</option><option value="357">Mitsubishi Fuso</option><option value="256">Morgan</option><option value="358">Motor Coach Industries</option><option value="398">Mullen</option><option value="359">Navistar</option><option value="360">New Flyer</option><option value="47">Nissan</option><option value="361">Nova Bus</option><option value="48">Oldsmobile</option><option value="289">Opel</option><option value="362">Orion</option><option value="363">Oshkosh</option><option value="115">Packard</option><option value="49">Panoz</option><option value="119">Peterbilt</option><option value="50">Peugeot</option><option value="364">Pierce</option><option value="295">Pininfarina</option><option value="51">Plymouth</option><option value="382">Polestar</option><option value="52">Pontiac</option><option value="53">Porsche</option><option value="365">Prevost</option><option value="381">Proterra</option><option value="54">RAM</option><option value="55">Renault</option><option value="386">Rivian</option><option value="397">Rizon</option><option value="56">Rolls-Royce</option><option value="389">Rosenbauer</option><option value="57">Saab</option><option value="58">Saturn</option><option value="366">Scania</option><option value="59">Scion</option><option value="396">SEA Electric</option><option value="367">Setra</option><option value="116">Shelby</option><option value="60">Smart</option><option value="368">Spartan</option><option value="62">Sterling</option><option value="95">Studebaker</option><option value="63">Subaru</option><option value="284">Sunbeam</option><option value="64">Suzuki</option><option value="369">Temsa</option><option value="919">Terberg Taylor</option><option value="370">Terex</option><option value="65">Tesla</option><option value="371">Thomas Built Buses</option><option value="372">Thomas Dennis</option><option value="870">TICO</option><option value="373">TMC</option><option value="66">Toyota</option><option value="88">Triumph</option><option value="183">UD Trucks</option><option value="374">Utilimaster</option><option value="375">Van Hool</option><option value="392">VinFast</option><option value="67">Volkswagen</option><option value="68">Volvo</option><option value="376">Western Star</option><option value="111">Willys</option><option value="377">Workhorse</option><option value="69">Yugo</option><option value="934">ZM Trucks</option> </select><span class="select2 select2-container select2-container--default" dir="ltr" style="width: 100%;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-MakeID-container"><span class="select2-selection__rendered" id="select2-MakeID-container"><span class="select2-selection__placeholder">Make</span></span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span> </div>

The code you suggested fails.

The code I used to populate a std. text field was like this and it works:

lnreturn = thisform.oAntviewDocument.SetElementValueByNameSync("VIN", "12345678901234567")

I tried this code for the dropdown and it fails, too:

lnreturn = thisform.oAntviewDocument.SetElementValueByNameSync("MakeID", "Toyota")

as does this code (your code, but using "thisfomr.oAntviewDocument"):

thisform.oAntviewDocument.ElementValueByName("MakeID") = "Toyota"

I'm wondering if they are changing this dropdown in some fashion via JavaScript. When I inspect it with Chrome Dev Tools, it doesn't show what I'd expect.
Reply
#4
This forum software seems buggy. I've had a lot of lock ups with the page becoming unresponsive.
Also, what's the best way to get rid of the quote of the previous response?
As for the question, I tried this:

lnreturn = thisform.oAntviewDocument.SetElementValueByNameSync("MakeID", "66")

and this:

lnreturn = thisform.oAntviewDocument.SetElementValueByNameSync("MakeID", 66)

Neither worked and lnreturn had a value of zero. Is it possible that the control is just not refreshing? Is there a way to do that? (I'll go looking for that next.)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)