I want to change the value of the input tag. But it's not working at all. I already found a working code that would change the value of the Select tag, but I haven't found a code that works well to change the value of the input tag below.
<div id="phmiddle_0_CheckoutShippingInfo1_selectAddressDiv" name="selectAddressDiv">
<select class="selecta" name="selAddressBook" id="selAddressBook">
<option value="-1">Create a new address</option>
<option value="{adbd6ae0-abf8-40ea-a18a-998afaeb37ad}">AAA AAA</option>
<option value="{0e0e26a0-c490-476f-9a00-d3d76d7d69cd}">BBB BBB</option>
<option value="{84496563-8dcb-42e6-b728-60646faf81d0}">CCC CCC</option>
</select>
<input type="hidden" name="idOfShiptoDefaultedToOrSelected"
id="idOfShiptoDefaultedToOrSelected"
value='{adbd6ae0-abf8-40ea-a18a-998afaeb37ad}' />
</div>
This is the code I used to try to change the hidden input value.
private void button9_Click(object sender, EventArgs e)
{ webBrowser1.Document.GetElementById("idOfShiptoDefaultedToOrSelected").SetAttribute("value", "-1");
}
It wouldn't work at all. Am I missing something here like a select or click? I already tried them.
I also tried this one too
webBrowser1.Document.GetElementById("selAddressBook").SetAttribute("value", "-1");
^ THAT code can change the seladdressbook but it wouldn't change the input hidden value, which is idOfShiptoDefaultedToOrSelected.
Why not do it in JavaScript:
$("#BUTTON_ID").click(function() {
$("idOfShiptoDefaultedToOrSelected").val("NEW_VALUE");
});
Related
I’m currently creating a page which displays information based on what’s selected from the drop-down.
My current select list looks like this
<Select id="Person" class="form-select" bind-value="#VisitDTO.Id" style="width: 500px" #onchange="() => #VisitSelected(5)">
<option value="0">Ivco Ref:</option>
#foreach (var visits in Visits)
{
<option value="#visits.Id">#visits.Id</option>
}
</Select>
As you can see, I've hardcoded the parameter to visitid: 5 - What could I put in the #VisitSelected method (or anywhere else) to bind that to the actual visitid field?
#onchange EventCallback passes a ChangeEventArgs parameter to your event handler which you can use to determine the selected value.
<select id="Person" class="form-select" value="#VisitDTO.Id" style="width: 500px" #onchange="VisitSelected">
<option value="0">Ivco Ref:</option>
#foreach (var visits in Visits)
{
<option value="#visits.Id">#visits.Id</option>
}
</select>
#code {
void VisitSelected(ChangeEventArgs e)
{
var selectedValue = e?.Value?.ToString();
// do other stuff
}
}
I changed the control to use Telerik Autocomplete in the end. Created a 2nd method which converted string to int, and then called another method to render what it needed to on the page.
I have this bit of HTML which should call /nodes/calibratePH?value=afloatnumber:
<div style="float:left; width:50%; margin-bottom:30px;">
<h3>PH calibration</h3>
<form id="CalibrationBar" action="/Nodes/CalibratePH" method="post">
<select id=ids type="text" name="name">
<option value="0" disabled selected>name</option>
#{
foreach (var configuration in Program.CAN_Listener.KnownConfigID)
{
if (configuration.type == Web_App.Models.Sensor_Types.PH)
{
<option value="#configuration.name">#configuration.name</option>
}
}
}
</select>
<input type="number" step="0.01" max="10.0" min="-10.0" placeholder="calibration value" name="value">
<input type="submit" value="calibrate PH">
</form>
The problem is, when I enter for instance: 3.09 or 3,09 (doesn't matter). The method CalibratePH in the controller(MVC, ASP.NET) gets the value: 309. 1.1 gives 11, and so forth. Does anyone have an idea how to solve this? I'm thinking about entering the input as text and evaluate the value upon recieval in the method, but that's not how it should be... right?
EDIT:
This guy seems to have sort of the same problem
I suggest you to make the parameter string on method calibratePH and when you receive it then cast it to float number.
using hidden field option in code behind.
Functionality for DDL selection is written in JQuery and assigned its value to hidden field. Now i want the text value where it is returning the index.
if you have HTML like this
<select id="YourDropDownSelectId" name="Name" onchange="SetSelectedText(this)">
<option value=""></option>
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3">test3</option>
</select>
<input type="hidden" id = "Yourinputid" name="InputName" />
You can add below by adding to asp page
<script type = "text/javascript">
function SetSelectedText(YourDropDownSelectId) {
var selectedText = YourDropDownSelectId.options[YourDropDownSelectId.selectedIndex].innerHTML;
document.getElementById("Yourinputid").value = selectedText;
}
</script>
and then retrieve using code behind like this inside your event handler
string Value = Request.Form["InputName"];
when i try to debug it is getting assigned by all the values of DDL as below. I need only one value get assigned.
I have put the options to a Drop Down list from a database using this code:
if (!IsPostBack)
{pageloaddata.retrievetbldata("Select EmpId, LastName+', '+FirstName+' '+MiddleName AS EmployeeName from Employee");
DropListEmployeeName.DataSource = pageloaddata.SQLTable;
DropListEmployeeName.DataTextField = "EmployeeName";
DropListEmployeeName.DataValueField = "EmpID";
DropListEmployeeName.DataBind();
DropListEmployeeName.Items.Insert(0, "Select")
}
So the Employee Name's value must be their Employee ID (EmpID)
Now what I want to happen is, if the user have selected an employee, the selectedValue(which is the EmpID) must be displayed into a textbox. Here's the little code I create and doesnt work, It may be very easy to others I know please help a beginner here thank you :)
protected void DropListEmployeeName_SelectedIndexChanged(object sender, EventArgs e)
{
string empSelected = DropListEmployeeName.SelectedValue.ToString();
employID.Text = empSelected;
}
Note: the EmpID in the database is actually an int, does it matter if I call it as string? If yes please suggest the best code
If you want to use Jquery to capture the value of your DropDown when it change take a look at this example I made click here or run the code snippet below.
$(document).ready(function () {
$("#SelectId").change(function () {
var selectObj = $(this);
$("#inputID").val(selectObj.val());
});
});
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</head>
<body>
<select name="mySelect" id="SelectId">
<option value="FirstOption">First Option</option>
<option value="SecondOption">Second Option</option>
<option value="ThirdOption">Third Option</option>
<option value="FourthOption">Fourth Option</option>
</select>
<input id="inputID" type="text" name="sampleText" />
</body>
</html>
But if you really want to use the Postback method from your DropDown control try this one.
<asp:DropDownList ID="DropListEmployeeName" runat="server" AutoPostBack="True"
onselectedindexchanged="DropListEmployeeName_SelectedIndexChanged">
</asp:DropDownList>
check your dropdown AutoPostBack="True" property.
string empSelected = Convert.Tostring(DropListEmployeeName.SelectedItem.Value);
other way
var empSelected = ((DropDownList)sender).SelectedValue;
string semSelected = selectedValue;
For some reason the dropdownlist's initial value doesnt get set. It always loads some random value instead. When I look into the markup I can see all the list items including the one with -1 value. I also tried clearing browser cache and explicitly setting the SelectedIndex/Value in code to 0/"-1", but cant seem to figure out what is going on. Any idea?
Here is how I am doing it:
<asp:DropDownList ID="ddlGender" runat="server" CssClass="select_Box" OnPreRender="LoadGenders">
</asp:DropDownList>
<div class="error">
<asp:RequiredFieldValidator
ID="RequiredFieldValidatorGender"
Runat="server"
Enabled="true"
InitialValue="-1"
ControlToValidate="ddlGender"
SetFocusOnError="true"
Display="Dynamic">Gender Required</asp:RequiredFieldValidator>
</div>
Generated HTML:
<select name="pagecolumns_0$pagecontent_1$contentleftcol_0$ctl00$ddlGender" id="pagecolumns_0_pagecontent_1_contentleftcol_0_ctl00_ddlGender" class="select_Box">
<option value="-1">--Select Gender--</option>
<option selected="selected" value="M">Male</option>
<option value="F">Female</option></select>
as you can see, it is randomly selecting Male. Alsow, I notice that, last time I fill the form I set it to Male before hitting submit. May be is it caching the selection?
Here is the .cs:
protected void LoadGenders(object sender, EventArgs e)
{
if (IsPostBack) return;
((DropDownList)sender).Items.AddRange(Constants.GenderWithSelect);
}
public static ListItem[] GenderWithSelect = (new[] { new ListItem("--Select Gender--", "-1") }).Concat(Gender).ToArray();
public static ListItem[] Gender = new[]
{
(new ListItem("Male","M")),
(new ListItem("Female","F"))
};
I tried your code, and it appears that the generated html didn't have the correct field bound to the "value" of the select options.
What you must get must have this format :
<select name="ctl00$MainContent$ddlGender" id="MainContent_ddlGender" class="select_Box">
<option selected="selected" value="-1">not set</option>
<option value="0">0</option>
<option value="1">1</option>
</select>
In order to have this, I had to set the DataValueField of the DropDownList:
<asp:DropDownList ID="ddlGender" runat="server" CssClass="select_Box" OnPreRender="ddlGender_PreRender" DataValueField="Value" DataTextField="Text">
(Just replace the DataTextField and DataValueField with the name of the properties of your class)
It turns out it has something to do with load sequence of the controls. So, adding selectedindex to LoadGenders did the trick.
protected void LoadGenders(object sender, EventArgs e)
{
if (IsPostBack) return;
((DropDownList)sender).Items.AddRange(Constants.GenderWithSelect);
((DropDownList) sender).SelectedIndex = 0;
}