jQuery select tag IE8 issue - jquery-selectors

I have two selects that initially render this way in both firefox and IE8:
<select id="cntctMap_PRSNL_TITL_TXT" >
<option value="Dr.">Dr.</option>
<option value="Ms.">Ms.</option>
<option value="Mrs.">Mrs.</option>
<option selected="" value="Mr.">Mr.</option>
</select>
<select id="cntctMap_CUST_SEGM_US_RETAIL_SALES_SMA"">
<option value="01">Focus</option>
<option value="02">Prospect</option>
<option value="03">Center Of Influence</option>
</select>
So far so good as only the first select has a value returned from the server-side, the second does not.
On document load I pull the html for the second select, i.e. $("#cntctMap_CUST_SEGM_US_RETAIL_SALES_SMA").html());
In IE the returned string is:
<option selected value="01">Focus</option><option value="02">Prospect</option><option value="03">Center Of Influence</option>
Notice the 'selected' attribute
But in firefox it's:
<option value="01">Focus</option><option value="02">Prospect</option><option value="03">Center Of Influence</option>
The reason this is important to me is that I want to prepend an option, i.e.
$("#cntctMapCUST_SEGM_US_RETAIL_SALES_SMA").prepend(selectOption);
And have the prepended option value show in the dropdown box, but I only want to do this for those selects that don't have a server-side value.
In IE, I can't tell which is which since 'selected' comes back in all cases. This is also true if I use $("#cntctMap_CUST_SEGM_US_RETAIL_SALES_SMA option:selected")); In IE, it always returns a 'selected' option.
Anyone know a way around this?

As discussed in the comments, I suggest adding a special class (e.g. has-default) to selects that have server-side values. This is done on the server-side when you render the tags.
<select id="cntctMap_PRSNL_TITL_TXT" class="has-default">
<option value="Dr.">Dr.</option>
<option value="Ms.">Ms.</option>
<option value="Mrs.">Mrs.</option>
<option selected="" value="Mr.">Mr.</option>
</select>
<select id="cntctMap_CUST_SEGM_US_RETAIL_SALES_SMA">
<option value="01">Focus</option>
<option value="02">Prospect</option>
<option value="03">Center Of Influence</option>
</select>
...
Using jQuery, you can target selects with server-side values:
$('select.has-default').prepend(selectOption);
The above statement will only prepend selectOption to selects that have the has-default class. This is more consistent because it doesn't rely on whether browsers mingle with the <option> tags.

Related

AutoHotKey: How to get list of available values from drop down list?

I am trying to automate a website to get data. Usually if I know in advance what are the possible value from the drop down list, I can hard code them in my script.
But if I don't know what are the values, is there an elegant way to dynamically obtain the drop down list values?
Working sample from: https://autohotkey.com/boards/viewtopic.php?t=15574
select name="ConnectDTO.EvaluationGroupId" id="ConnectDTO_EvaluationGroupId" style="width: 260px;" required="yes" data-val-number="The field Evaluation Group must be a number." data-val="true"><option value="">Please Select</option>
<option value="4">ccpdmanagement</option>
<option value="7">AM Northern</option>
<option selected="selected" value="3">cwplanning</option>
<option value="1">mnplanning</option>
<option value="2">msplanning</option>
<option value="9">LCC</option>
<option value="6">powerquality2</option>
<option value="8">AM Southern</option>
<option value="5">tcoqueries</option>
</select>
When my script arrived on the page after loadIE(wb), is there a way to "get" the list of selection - such as ccpdmanagement, AM Northern etc...?
I know how to select them once the option is known in advance only.
pwb.document.getElementById("ConnectDTO_EvaluationGroupId").Focus()
pwb.Document.GetelementById("ConnectDTO_EvaluationGroupId").value := "1"
Thanks.
I found a solution here: https://autohotkey.com/boards/viewtopic.php?t=35467
Althought the Author stated he has a problem with the code (stated not work for some reason).
But for my purpose - to retrieve the list of all the drop down list option. It worked fine.
myDropDownList := wb.document.getElementById("your_dropdown_ID")
loop % myDropDownList.length
{
test := myDropDownList[A_Index-1].value
MsgBox %test%
}

TYPO3 form - select an option from select box with get parameter

I'm trying to have a TYPO3 request form that is called from a simple link with a parameter, e.g.
request
The TYPO3 form has a select box with some options:
<select id="field-10" name="tx_form[Product-line]">
<option value="11">Product 1</option>
<option value="12">Product 2</option>
<option value="13">Product 3</option>
</select>
How can I preselect the option with a get parameter here?

Liftweb form processing

How do I test to see which option is in focus during a form submittal?
<select name="temp" id="keys">
<option selected="selected" value="ISBN">ISBN</option>
<option value="Title">Title</option>
<option value="Author">Author</option>
<option value="Publisher">Publisher</option>
<option value="Date">Date</option>
</select>
From my snippet I've tried S.param("temp")...
A common way to do this is use SHtml.select()
This way you can have the options taken from Scala code, in a typesafe manner and prone to typos.
As far as I understand, S.param("temp") should work also, if you din't mess with the <form>.

How to set custom data attbributes with zend form select?

I am using Zend_Form_Element_Select to create a select form element. Here's how the inner HTML is rendered:
<option value="9" label="Biscuits">Biscuits</option>
<option value="10" label="Scones">Scones</option>
<option value="11" label="Cakes">Cakes</option>
Now, I want to be able to include a custom data attribute, data-qty, with each option, per the following example:
<option value="9" label="Biscuits" data-qty="27">Biscuits</option>
<option value="10" label="Scones" data-qty="12">Scones</option>
<option value="11" label="Cakes" data-qty="21">Cakes</option>
I can't see any way to do this out of the box so I think I'll need to extend the select element, create a new decorator, or some such solution. Any ideas?

Select the first element of a list with prototype

I have a form with 3 lists like this and I need every time one of the lists change put the others in cero 0, I need this in prototype or pure Javascript
<select id="1" onchange="resetall()">
<option value="0">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="2" onchange="resetall()">
<option value="0">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="3" onchange="resetall()">
<option value="0">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
thanks.
Here's a working demo using Prototype
Basically, it finds all select elements with the class resetOthers, and listens for the onchange event (don't use the onchange HTML attribute - it's cleaner to add the JavaScript behavior via JavaScript once the page has loaded).
When a select changes, it loops through the select elements, and sets each to the value of the first option (except for the one that triggered the event, of course).