Get the last Select option value from a webbrowser control VB6 - javascript

I need to get the value of the last option, from a box. "SelCONTACTS"
I have a webbrowser control in VB6 and i have it source code in a TextBox
<select name="SelCONTACTS" onchange="javascript:setTimeout('__doPostBack(\'SelCONTACTS\',\'\')', 0)" id="ctl00_ContentPlaceHolder1_ddlContratos">
<option selected="selected" value="30393">6-4002582</option>
<option value="194177">A-70P0096</option>
<option value="220499">B-7000902</option>
</select>
the name SelCONTACTS is a fixed name, it wont change. VALUES and CONTENTS of LIST ITEMS do change.
Only thing i can imagine is to search for the string and go a couple spaces back (but thats an horrible way to do it)
</option>
</select>

Related

<s:select> drop down issue when using default option as empty

I am using Map to populate Struts2 tag <s:select > , observed that when there are multiple submission of the form a blank line gets appened at the end of the list.
For instance, if Map has 2 key value pairs it show 3 records and append a blank record in the bottom(not at the top--for default case).
Item 1
Item 2
<-blank->
<s:select id="bankAccountId"
name="accountBean.recordDetails.BankAcct.bankAcctId" label=""
headerKey="" headerValue="" list="accountBean.bankAccountMap"
listKey="key" listValue="value" />
<select name="accountBean.recordDetails.BankAcct.bankAcctId">
<option value=""></option>
<option value="51089">BANK XXXX123</option>
</select>
<select name="accountBean.recordDetails.BankAcct.bankAcctId" id="bankAccountId"> <option value="-1" selected="selected">Default values</option> <option value="77746">Details XXXXXX2246</option> <option value="-1" selected="selected"> </option> <---this default value gets appened in the end... </select>
When i use s:select attribute emptyOption="true" same issue is observed but when emptyOption="false" top element becomes non-empty(which i dont want).
on re-submission
<option value="" selected="selected"> </option> extral option gets appened if prior to resubmission default/empty value was chosen..
Can this be handeled by javascript or jQuery??
As things seem, I think the problem is that you are adding the default value to the map after submission, so in the next rendering of the page, it already contains that item. Usually, you should refill your map in your prepare method, that way the -1 key won't be in the map.

parsley.js select list value of zero - not working

I have a select list on my test form that I am trying to get to work with parsley.js validation.
The parsley validation does work, but only when the default value of the select list is a blank value, except I need to have a value of 0 (zero).
So when the value of zero is selected / displayed in the select list the select list should be red with indicating that there is an error.
How do I get the select list to validate correctly, when I am using a default value of zero?
Here is an example of my select list with the zero value:
<select name="availability_type" id="id_availability_type" data-parsley-id="1601" data-parsley-required="true" data-parsley-required-message="You must enter at least one Detail." class="input-xlarge2 standard_input_style parsley-success">
<option value="0"> Do not display Availability</option>
<option value="1">Immediately</option>
<option value="2">1 week</option>
<option value="3">2 weeks</option>
<option value="4">3 weeks</option>
<option value="5">4 weeks</option>
<option value="6">> 4 weeks</option>
</select>
Here is the code line that works with a blank space as the value:
<option value=" "> Do not display Availability</option>
I finally got this to work using the data-parsley-min="1".
This way the input will not accept the value of zero.
Hope that this helps some one.
To make it work properly you needed to do the following
<!--Do this-->
<select id="select-id" required="" data-parsley-required-message="You must select at least one option.">
<option value=""> Do not display Availability</option>
.
.
</select>
Doing it witht data-parsley-min="1". would make your required message say something stupid like min value has to be at least 1 (even if you override it with the required message attribute)
Hope this helps any other person...

Changing two select options value via javascript

there are two option controls in a website:
<select class="operator" name="operator" id="operator">
<option value="0">Entekhab Operator</option>
<option value="1">Irancell</option>
<option value="2">Talia</option>
<option value="3">HamraheAval</option>
</select>
<select class="card" name="chargeCard" id="chargeCard">
<option value="0">Entekhab Sharj</option>
</select>
When a user changes the first one by clicking on that (and selecting an option), the second one will also change...as you see in the above code, the second option has no value and will get some values after clicking on the first one
My problem is that I have to change them via javascipt in my android program
I tried with the following:
document.getElementById("operator").value=2
and this way i changed the first one.
But the second one does not change and dose not get values! What should I do for the second option to change as well?
maybe i didnt explain my question very well. i changed the value of the option but i needed something like stimulating the change event.
this code solved my problem:
$('#operator').trigger('change');

Setting the value of an html element programmatically

I'm trying to create auto responder message templates with respect the the subject the visitor chooses. I checked formmail and I found how it's done as in setting up templates to be picked up from fmtemplate directory.
http://www.tectite.com/fmhowto/autorespond.php
However, before the auto-responder sends anything, I'd need to check the "Subject" selection and send the appropriate auto-responder template.
The way I think it should be done is as follows. Have the values of the select tag set like the following.
<select name="subject" id="subject" class="subject_category"">
<option value="first_option">First Option</option>
<option value="second_option">Second Option</option>
<option value="third_option">Third Option</option>
<option value="fourth_option">Fourth Option</option>
</select>
And some how have the following hidden tag instructed by formmail
to replace the file name of the autorespond HTML into the option chosen by the user.
Is there a way to embed javascript in place of arhtml.html file so it reads off the select option and constructs a html name accordingly?

why the default select drop list doesn't change?

<form method="get" action="http://example.com/" name="currencies">
<div>
Currencies:
<select onchange="this.form.submit();" class="select" name="currency">
<option value="USD" selected="selected">US Dollar</option>
<option value="EUR">Euro</option>
<option value="GBP">GB Pound</option>
<option value="CAD">Canadian Dollar</option>
<option value="AUD">Australian Dollar</option>
</select>
<input type="hidden" value="index" name="main_page"/>
</div>
</form>
when i select the GB Pound, all the function is ok except that the default selected is still US Dollar.when i delete the selected="selected" in <option value="USD"... when i change to Australian Dollar. the item shows on the select drop list is still US Dollar. why?
The "default" selection applies when the page first loads, and will be either the option with the "selected" attribute, or the first option when none were specified as "selected".
The View Source facility shows what the browser originally received from the webserver, not the current state of everything on the page after the user (or JavaScript) has changed things.
If you use JavaScript to get values of fields (e.g., in response to some user action) the current values will be reported.
When you submit the form, the current values of your form fields will be sent to the web server and can be accessed by your server-side code.
If the result of submitting the form is to redisplay the same page and you want the previously selected option to still be selected then you should use server-side code to apply the "selected" attribute to the appropriate option. What server-side technology are you using? PHP? (Or JSP, .NET, ...?)
When you choose "Australian Dollar" the action url will have "currency=AUD" but the HTML code itself does not change. The selected="selected" still stays with the US Dollar.
You could use some simple jQuery to move the selected attribute if you like in the DOM, but if you refresh the page, you will still have the same, original HTML you started with.

Categories