This is a really simple problem I can't figure out. I am trying to get the value of a dropdownlist using Javascript. I have 4 digit job codes in my dropdownlist. On a button click I got to this function and am trying to get the value of what was selected when a button was pushed.
function jobCodeToAdd() {
var jobCode = document.getElementById("<%=jobCode.ClientID%>"));
var selectedJobCode = jobCode.options[jobCode.selectedIndex].value;
What am I doing wrong? Thank you for your help.
I think what you are looking for is .text
var jobCode = document.getElementById("<%=jobCode.ClientID%>"));
var selectedJobCode = jobCode.options[jobCode.selectedIndex].text;
Related
I want to update the value of text box from where I'm getting initial value to add product to cart.
Now I'm applying round function & I want to update the value of text box that is because I'm using ajax & if I'm applying round function, user must know how system calculated everything.
Here's my simple code:
<script>
$(document).ready(function(){
$(document).delegate('.purchasenow','click', function(e){
var buynow=this;
var productid = $(this).attr('id');
var quantity = $('.quo_'+productid).val();
var quantity = Math.round(quantity);
alert(quantity); //This gives the value
$('.quo_'+productid).value = quantity; //This is not working
});
});
Can anyone tell why it's not working? It's very simple but I'm not able to find out the cause.
Have you tried
$('.quo_'+productid).val(quantity);
The jQuery selector returns a wrapped object, not the actual DOM element. I don't think wrapped object has the .value property
you are almost correct the only thing why it is not working because your syntax is wrong
this is the correct syntax for jQuery
$('.quo_'+productid).val(quantity);
if you want it in javascript
var txt = document.getElementById("quo_"+productid);
txt.value = quantity;
I have hopefully a simple javascript problem.
I am trying to get the value of a drop down box to help create a dynamic URL. The problem is I am a Javascript novice and where the value should appear in the URL it says "undefined"
This is the script:
var imgcon = document.getElementById('imgcon');
var imgconval = imgcon.value;
function getdata(id){window.location = "index.php?id="+id+"&img="+imgconval;}
'imgcon' is a drop down box and the number values are appearing correctly when viewing the ource code. Does anyone know how to have var imgconval show the value and not say undefined?
Thanks
Create an onchange event:
document.getElementById('imgcon').onchange = function() {
var imgconval = this.value;
}
Im having a terrible time trying to calculate the value of two form fields. I'm constantly getting "NAN" which would indicate non-numeric input, this is despite the fact that the form fields are only populated with numbers.
In response I tried to use ParseInt to get a numeric value. This also fails to yield a successful result.
This is what I have so far. Any help is appreciated.
$('#value-calc input').change(function () {
var valueINT = parseInt($('#value'),10);
var quantINT = parseInt($('#quantity'), 10);
var math = ((valueINT/quantINT)*1000);
$('#cpm').val(math);
});
http://jsfiddle.net/greyoxide/YRWAA/1/
You need to add the .val() method after your selectors to get the value they hold
working fiddle
You're not passing in strings when you refer to elements by ID with that jQuery.
Perhaps try $('#value').val() in the parseInt methods instead.
Try this:
$('#value-calc input').keyup(function () {
var valueINT = $('#value').val();
var quantINT = $('#quantity').val();
var math = ((valueINT/quantINT)*1000);
$('#cpm').val(math);
});
I have a select list with dynamic content such
Honorar, 120.00
Porti, 7.50
Spesen, 12.00
This values are stored x_ko_leistungsart. I am selecting only one option (no multi selection) and would like to have the values after comma such 120.00 for Honorar and 7.50 if the the option porti is selected.
I am using the following function to get these values. unfortunately it does not work. I get only the value 10 assiged...
Could you please have a look to the code where the mistake can be?
Regards
thanks
mpol_ch
function SelectAnsatz() {
document.fkostenedit.x_ko_ansatz.value = '10';
var Ansatz=0;
var splitted;
var elements = document.getElementsByName("x_ko_leistungsart[]");
splitted = elements.nextSibling.nodeValue.split(",");
Ansatz = parseFloat(splitted[1]);
document.fkostenedit.x_ko_ansatz.value = Ansatz.toFixed(2);
}
Take a look at document.getElementsByName("x_ko_leistungsart[]");
I'll give you a hint: The "value" you're getting from that is not what you're expecting. You can reduce at least two lines of code by expanding on the getElementByName function.
You can find more information here: http://www.w3schools.com/dom/dom_nodes_get.asp
I solves my problem with an onchange even on x_ko_leistungsart. Here is the function:
Thanks
mpol_ch
function SelectAnsatz(){
var x=document.getElementById("x_ko_leistungsart");Ansatz=x.options[x.selectedIndex].text.split(",");
document.fkostenedit.x_ko_ansatz.value = Ansatz[1];
}
I have the following code:
var tempIdx = document.getElementById('cityBuild').selectedIndex;
var tempBuilding = document.getElementById('cityBuild').options[tempIdx].value;
// Do stuff with tempBuilding
I spent some time trying to do it in jQuery under the assumption it'd be easier, it wasn't. I tried what was given at this site but is never returned any of the values. Am I doing something wrong or is this something that jQuery simply doesn't do?
The item is a select box (single selection only) and I want to get the value from it.
jQuery knows how to work with select elements. You can get the value as any other input:
var value = $('#cityBuild').val();
Little variation to Eran answer:
var value = $('#cityBuild option:selected').val();
EDIT: now Eran is in the right. :)