I'm using this example of nested cascading selects http://jsfiddle.net/jhsousa/Mekhy/ ... I've got it in a form which when submits emails the values of the select options through. I've added NAME="" and ID="" to achieve this. However only a number is sent through.
How can I get the selected option .value to equal the .text which it is populated by?
This is my first experience with Angular so not having any joy.
I tried adding:
obj.value as obj.text for obj in array
to the ng-options. But the entire thing stopped working because ng-options already has a value.
Thanks.
There is no NICE way to get the text.
The only way is to activate a function call that loop through the Dropdown options elements and find the correct ID and extract the text from the optons.
Related
I have a form I created in pdf that basically has a dropdown with the student's names that uses their Student ID's as the values. Pretty straightforward. I am able to populate another field (textbox) with the value of the selected item in the dropdown. Works great. I have searched in whatever ways I know how, but I am unable to find an answer to this question:
I have a second dropdown that I very simply want to populate with the same selected index as the first. In other words the selected indexes of both dropdowns will always match each other (I don't need a two way function, I just want the second dropdown to match the first.). I don't know of a way to assign two values to each dropdown item or I would try that. In theory, this problem seems like it should be really simple to solve, but I guess that's what makes me, me.
Here is the simple code I use to get the value from the dropdown and populate the textbox:
event.value = this.getField("Fieldname").value;
Thank you.
After much experimentation, I finally realized there actually IS a simple way to do this. Let me try to explain. The first dropdown has student names using their student ID's as the VALUES. The ID text box pulls the values from the selected name to display the id number. I needed the third dropdown field to display the address. Here's how simple that was:
I called the value from the textbox (which was the student ID). I set up the third dropbdown to have the address as the display and the Student ID as the VALUE of the address. I then just set it up like the iroginal:
event.value = this.getField("Fieldname").value;
Voila! It now displays the address in the third field.
It seems like you can actually daisy chain this method repeatedly to autofill even more fields if you needed to.
I have a select box in my webpage to fill a formulary. I want to recover the info filled by the user other times in it exists.
All my fields are properly filled except select box.
This is my code in html related to selectbox:
<br>Gender: <select id="gender">
<option value="man">Man</option>
<option value="woman">Woman</option><br>
It is a simple webpage just with a formulary in it. There is not anything else. I am just trying it.
With this line:
$(document).on("pageinit", '#settings', function() {
document.forms[0].gender.value = userGender;
...
I am modifiying the value of that box for reading it in other parts of my webpage or send it to the database. And the value keept is the correct one, but, the displayed value is not propertly shown.
Do you know which property do I have to modify to change the displayed value?
According to your question the asnwer developerCK has provided is correct.
Anyway look this demo and give a feed back if any thing we missed.
$('#gender').val('woman');
If you are using jQuery, then you can change or select the value of select box through jQuery!
It is very easy. Use selector and val.
$('#gender').val(userGender);
I have an HTML select element (combo box) in a form with a couple if options in it. As always each option has a specific value. During the page's initialization I get a value from the server that I must use as the selected option in the list. Sometimes however I get a value from the server that does not match any of the available options. (grrrr)
I want to let the user know that the value I got from the server is not a valid option. What I'd like to do is show an empty select box (as if no selection was made) without having an actual empty option as one of the options. Also I'd like to use the default select element if possible. Is something like this possible?
Edit: When you set the value for a combox to '' in IE9 (I used $('select').val('') ) it empties the text in the combo box which is exactly what I need. Unfortunately only IE9 does this, so this is not an option.
Out of the box, HTML selects do not provide such functionality. You will have to add an empty <option value="somethingwrong">Please, pick a value</option> element and use scripting to check if the user has selected this specific value. I'd suggest catching both onchange event of the dropdown and onsubmit event of whole form.
You can insert option in select, and remove that whenever it is changed to reduce problems with that options
Check the Demo here
I have been using the jquery serialize() function to serialize the values of a form and submit it via ajax
like for e.g. if the form name and id is factoryUsers
var data=$("#factoryUsers").serialize();
Now this works fine for forms that have text fields, text areas, simple drop downs etc.
But when I have a multiple dropdown , things go awry
for e.g. if I have a dropdown of the type
<select size="5" id="factoryUsers" name="factoryUsers" multiple="multiple">
the serialize doesn't work correctly anymore.
so if I select 3 users I get a query string like
factoryUsers=5&factoryUsers=23&factoryUsers=11
changing the select to array type doesn't help either factoryUsers[]
Any idea or help how to get this working correctly would be great.
Try changing the name of the select to factoryUsers[]. That way you can loop through it in your backend.
The string output you've described above is the correct way of submitting multiple values for forms with the same name over HTTP, so jQuery is working correctly. It's up to you to handle how this is processed on the server-side, which is then dependent on what language you are using.
If you're using PHP, this may help: http://bytes.com/topic/php/answers/12267-how-php-_post-gets-multiple-values-html-form
Can you tell us what language you're using?
All you need is change name="factoryUsers" to name="factoryUsers[]" PHP will treat it as array.
Your elements name must be array type factoryUsers[]
Change your code this:
<select size="5" id="factoryUsers" name="factoryUsers[]" multiple="multiple">
Thanks...
Just try it to get value with val()
data='factoryUsers=' + $("#factoryUsers").val();
It will give you the values with comma seperate.
factoryUsers=1,2,4
If this item is one of your form. Then try to add the value of item end of the serialize. Example:
data= f.serialize() + '&factoryUsers=' + $('#factoryUsers').val();
Since, the item written twice into the request, the last value will be valid in controller.
You can use the PHP function
parse_str($_POST)
This function seems to be an extract function. After you run this, you can access a var named $factoryUsers, and this var is an array $factoryUsers[n].
I want to be able to send all the selected values from a listbox as a hidden field using JQuery.
I was able to send/retrieve a single value on form submission.
If anyone can share some code snippet, that would help.
Thanks in Advance!
Well, it's not so clear what you are really asking for. There is no "multiple selection dropdownlist" in HTML. To have a multiselect you need to specify
<select id="foobar" multiple>
that will create a listbox where you may select multiple elements. Calling
var sel = $('#foobar').val();
will return an Array of selected items.
edit
To get the text from each option, use .map() or jQuery.map(). Example:
var sel = $('#foobar').children('option:selected').map(function(i,e){
return e.innerText;
}).get();
That will create an Array containing the text of all selected entrys.
There's absolutely no need to do like that. You was apparently using request.getParameter() instead of request.getParameterValues() and wondering why it returned only the first value.
Just fix your servlet code accordingly:
String[] selectedItems = request.getParameterValues("dropdownname");
No need for ugly JS/jQuery hacks to send them all as single parameter. In future questions, try to ask how to solve a problem instead of how to achieve a solution which may after all not be the right solution per se.