Dynamically change value of a <select> inside cell of a table - html

i'm developing an asp.net/vb.net webapp.
I've an html table with some columns.
I get the values of the cells from a database, so i've a dinamically number of rows.
In columns i need to put a tag, because i want to allow the user to change the value of that cell.
Of course the initial value of the select should have to come from the query, but i dont know how to do this.
Something like
...
<td> <select selected="<%= queryresult("id").value %>">
<option value="1"> option1 </value>
<option value="2"> option2 </value>
</select></td>
...
but obv not working.
I just hope you understand what i want.
Thanks.

You can find the solution for your problem posted here but implemented with PHP. Anyway you can do it with ASP.NET as well. Basically you have to check if the current option value has the value from the query and add selected="selected" to the specific option tag. Also the correct markup for a select is like this:
<select>
<option value="1" selected="selected">Option 1</option>
<option value="2">Option 2</option>
</select>

Related

HTML Form Get Method - ignore optional field

newbie here, so thanks in advance for help! I have a Wordpress site with multiple taxonomies. I'd like to create a very simple form with two select boxes, one for each taxonomy. Then I'd like to use an HTML form with the get method to display posts matching the criteria they requested from the select boxes.
I'm able to do this easy enough if each of the two select boxes are filled out, I get a permalink something like:
testsite.com/?tax1=value1&tax2=value2
(ugly, I know, but it works).
What I can't figure out is what to do if they don't fill out both select boxes. Ideally it would only give the permalink for the one they fill in, so either:
testsite.com/?tax1=value1 or testsite.com/?tax2=value2
But instead I'm getting
testsite.com/?tax1=value1&tax2=Select+tax
here is my HTML
<form action="http://www.testsite.com/" method="get">
Season: <select name="season">
<option>Select season</option>
<option value="">Select season</option>
<option value="spring">Spring</option>
<option value="summer">Summer</option>
<option value="fall">Fall</option>
</select><br/>
Vacation type: <select name="vacations">
<option value="">Select vacation type</option>
<option value="beach">Beach</option>
<option value="ski">Ski</option>
</select><br/>
<input type="submit" />
</form>
I realize the answer is probably simple but I'm banging my head against a wall so any help is very very much appreciated. Thank you!
You can still pass an empty parameter like
testsite.com/?tax1=&tax2=whatever_was_selected
or
testsite.com/?tax1=whatever_was_selected&tax2=
but, you would have to preselect one of the options for them like
<option selected="selected" value="">Select vacation type</option>
This way if the form is submitted and the user didn't change their selection it should still pass the parameter of but without a value.
You can put some Javascript or Php validation to make sure both the dropdown are selected before submitting the form.

Mass edit the value of an HTML form to match the name

I have a pretty big form with over 4000 values defined by the <option> tag.
I would like to match all values with the visible name. Currently it looks like this:
<option value="1">Name 1</option>
<option value="2">Name 2</option>
...
I would like to receive to achieve the following:
<option value="Name 1">Name 1</option>
<option value="Name 2">Name 2</option>
...
Can someone help me out with a solution?
This would be a perfect opportunity for in-editor jQuery, which I've been wanting a long time but have never found. So here's the next-best thing: find and replace with regular expressions! :D
Find:
<option(.+?)value=".*?"(.*?)>(.*?)</option>
Replace:
<option$1value="$3"$2>$3</option>
VoilĂ !

Does Native HTML have a ListBox element

Does native HTML have a listbox element? You know how it has a drop box element (called select), does it also have a listbox?
If not, do you know how I could place a list box in my Website.
One method, is to create a table & have each element detect the onclick event. But I dont want to make my own just yet. Are javascript widgets easy to use?
Use a select list:
<select multiple="multiple" size="2">
<option value="Whatever">One</option>
<option value="Other">Two</option>
</select>
#Myles has the select box which is correct, you can also allow multiple select options.
<select multiple="multiple">
<option value="opt1">Option 1</option>
<option value="opt2">Option 2</option>
<option value="opt3">Option 3</option>
</select>
Add the multiple attribute to a normal <select> and use the size attribute to determine how many rows you want shown. (If you don't set the size attribute, then all options will be visible.):
<select multiple="multiple" size="5">
See example.
I think what you need is the select tag, but set the selects attributes of multiple and size. Here is a reference http://www.w3schools.com/tags/tag_select.asp.
<select multiple='multiple' size='3'>
<option value='o1'>Red</option>
<option value='o2'>Green</option>
<option value='o3'>Blue</option>
</select>
At this moment the standards do not have a listbox element.
There's a web spec in progress about the <selectmenu> element which does have a listbox slot (not element). Possibly this could end up being back in the <select> element
If you want to read more about it:
https://open-ui.org/prototypes/selectmenu
https://css-tricks.com/the-selectmenu-element/

How can I hide one field of an HTML form?

I have a simple HTML form that I'm using to drive site search for a website I'm creating.
Two of the fields should not be used together, such as "make" and "model" of a car. You wouldn't want someone searching for a "Ford Ram Truck," for instance.
How can I modify my form so that if a certain value in one of the fields is selected, the other field disappears?
Thank you for your help!
<select name="make">
<option value="item 1">item 1</option>
<option value="item 2">item 2</option>
</select>
<select name="model">
<option value="item 1">item 1</option>
<option value="item 2">item 2</option>
</select>
<input name="" type="submit" />
You would need to use javascript and hook up to the change event of the radio buttons.
In your javascript you can set the visibility of any form element to hidden or visible (depending on which you want).
You would still need to validate/check on the server side in order to avoid such a search (since javascript may be off or a malicious user might override your client side validation).
I think Chained Select Menu can solve your problem.

Is there any way to have multiple ID:s with same name in one HTML document?

I have a form which has several tags.
is this possible:
<select name="select1" id="select1">
<option id="1990" value="1990">1990</option>
<option id="1991" value="1991">1991</option>
</select>
<select name="select2" id="select2">
<option id="1990" value="1990">1990</option>
<option id="1991" value="1991">1991</option>
</select>
The ID are the same...
Thanks
No id can be assigned only once since it is an identity for just a single element. You need to use class instead but i wonder why you need to assign same ids? If you assign same ids to more than one element, and use javascript, etc to manipulate it, then only last element with same id will be taken care of ignoring all previous elements....
For more information, please see:
ID vs CLASS