I want the output of my program to be sent to an MEdit box but for whatever reason the html method does not set the value of the box should I use an MLabel instead?
here is my code:
function MButton1Click(event)
{
var temp = $("#MEdit1").val();
temp = parseInt(temp);
var selectedItem = $("input[name='MRadioGroup1']:checked").val();
if(selectedItem == 0)
{
var five9ths = 5/9;
temp = temp - five9ths;
temp = temp + 32;
$('#MEdit3').html("C");
}
else
{
var nine5ths = 9/5;
temp = temp * nine5ths;
temp = temp + 32;
$('#MEdit3').html("F");
}
var temperature = temp.toString();
$('#MEdit2').html(temperature);
}
You need to use .val() instead of .html()
$('#MEdit3').val("C");
Here is what your code should look like :
function MButton1Click(event) {
var temp = $("#MEdit1").val();
temp = parseInt(temp);
var selectedItem = $("input[name='MRadioGroup1']:checked").val();
if (selectedItem == 0) {
var five9ths = 5 / 9;
temp = temp - five9ths;
temp = temp + 32;
$('#MEdit3').val("C");
} else {
var nine5ths = 9 / 5;
temp = temp * nine5ths;
temp = temp + 32;
$('#MEdit3').val("F");
}
var temperature = temp.toString();
$('#MEdit2').val(temperature);
}
Related
I am getting string -
["1-2","10-4","2-3","3-1","4-4","5-2","6-4","7-3","8-1","9-2"]
as output from GetOption function where event - QuestionID & event1 -OptionID
Project-Online Examination System
var getValue;
var getName = new Array();
var temp = new Array();
function GetOption(event, event1) {
debugger;
if (temp.includes(event)) {
var x = getName.indexOf(event);
getName.splice(x - 1, 1);
getName.includes(event);
}
this.event1 = event1;
temp.push(event);
var getValue = event + "-" + event1;
if (getValue == "undefined-undefined") {
getName.push("");
} else {
getName.push(getValue);
getName.sort();
alert(getName);
}
$("#resultHidden").val(getName);
}
var items = ["1-2","10-4","2-3","3-1","4-4","5-2","6-4","7-3","8-1","9-2"];
var searchItems = "1-2";
var newItems = "2-1";
for (var i = 0; i < items.length; i++) {
if (items[i].startsWith(searchItems)) {
items[i] = newItems;
}
}
Good evening, I am wondering if there is a way to cycle through multiple variables with a for loop?
I have many variables set, here is my code:
if (MedicalIndex11 == 1) {
if (MedicalIndex11 != MedicalIndex1) {
temp = Medical11.value;
Medical11.value = Medical1.value;
Medical1.value = temp;
} else if (MedicalIndex11 != MedicalIndex3) {
temp = Medical11.value;
Medical11.value = Medical3.value;
Medical3.value= temp;
} else if (MedicalIndex11 != MedicalIndex5) {
temp = Medical11.value;
Medical11.value = Medical5.value;
Medical5.value = temp;
} else if (MedicalIndex11 != MedicalIndex7) {
temp = Medical11.value;
Medical11.value = Medical7.value;
Medical7.value = temp;
} else if (MedicalIndex11 != MedicalIndex9) {
temp = Medical11.value;
Medical11.value = Medical9.value;
Medical9.value = temp;
} else {
}
EDIT: Here is a working sample of the code with a for loop, and arrays:
for (i = 10; i < 30; i++) {
if (IndexArray[i] == 1) {
if (IndexArray[i] != MedicalIndex1) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical1.value;
Medical1.value = temp;
} else if (IndexArray[i] != MedicalIndex3) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical3.value;
Medical3.value= temp;
} else if (IndexArray[i] != MedicalIndex5) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical5.value;
Medical5.value = temp;
} else if (IndexArray[i] != MedicalIndex7) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical7.value;
Medical7.value = temp;
} else if (IndexArray[i] != MedicalIndex9) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical9.value;
Medical9.value = temp;
} else {
}
}
}
I ran the code, and the syntax seems to be fine, but it doesn't want to swap the values of the variables. I am getting the Medical variables from user input from a PDF document
EDIT 2: The Medical variables are found by user input on a PDF form, here is the code:
var Medical1 = this.getField("Medications 1");
var Medical3 = this.getField("Medications 3");
var Medical5 = this.getField("Medications 5");
var Medical7 = this.getField("Medications 7");
var Medical9 = this.getField("Medications 9");
var Medical11 = this.getField("Medications 11");
var Medical13 = this.getField("Medications 13");
var Medical15 = this.getField("Medications 15");
var Medical17 = this.getField("Medications 17");
var Medical19 = this.getField("Medications 19");
var Medical21 = this.getField("Medications 21");
var Medical23 = this.getField("Medications 23");
var Medical25 = this.getField("Medications 25");
var Medical27 = this.getField("Medications 27");
var Medical29 = this.getField("Medications 29");
var Medical31 = this.getField("Medications 31");
var Medical33 = this.getField("Medications 33");
var Medical35 = this.getField("Medications 35");
var Medical37 = this.getField("Medications 37");
var Medical39 = this.getField("Medications 39");
var MedicalIndex1 = 0
var MedicalIndex3 = null
var MedicalIndex5 = null
var MedicalIndex7 = null
var MedicalIndex9 = null
var MedicalIndex11 = null
var MedicalIndex13 = null
var MedicalIndex15 = null
var MedicalIndex17 = null
var MedicalIndex19 = null
var MedicalIndex21 = null
var MedicalIndex23 = null
var MedicalIndex25 = null
var MedicalIndex27 = null
var MedicalIndex29 = null
var MedicalIndex31 = null
var MedicalIndex33 = null
var MedicalIndex35 = null
var MedicalIndex37 = null
var MedicalIndex39 = null
var MedicalArray = ["DEPRESSION", "ANGINA", "BIPOLAR DEPRESSION",
"ATHEROSCLEROSIS", "HEART ATTACK"];
var temp = 0
The objective is to swap the variables that have any of the listed diagnoses from the MedicalArray, so that the first 5 Medical variables contain one of the several strings in the Medical Array.
What do you think about a solution like this?
if (MedicalIndex11 == 1)
{
var i;
for(i=1;i<=9;i+=2)
swap(11,i);
}
else
{
}
function swap(a, b)
{
var temp;
if (window['MedicalIndex' + a] == window['MedicalIndex' + b]) return;
temp = window['Medical' + a].value;
window['Medical' + a].value = window['Medical' + b].value;
window['Medical' + b].value = temp;
}
I have tried to do the calculation of the marks obtained and want it to display in a table. As in the javascript, the calculation that i have did is as below:
<script>
function kira1() {
var myeBook = document.getElementById('eBook').value;
var result = document.getElementById('result1');
var myResult = myeBook * 3;
result.value = myResult;
}
function kira2() {
var mybukuTeks = document.getElementById('bukuTeks').value;
var result = document.getElementById('result2');
var myResult = mybukuTeks * 3;
result.value = myResult;
}
function kira3() {
var mymodul = document.getElementById('modul').value;
var result = document.getElementById('result3');
var myResult = mymodul * 2;
result.value = myResult;
}
function kira4() {
var myjurnal = document.getElementById('jurnal').value;
var result = document.getElementById('result4');
var myResult = myjurnal * 2;
result.value = myResult;
}
function kira5() {
var myePembelajaran = document.getElementById('ePembelajaran').value;
var result = document.getElementById('result5');
var myResult = myePembelajaran * 1;
result.value = myResult;
}
function kira6() {
var myinovasi = document.getElementById('inovasi').value;
var result = document.getElementById('result6');
var myResult = myinovasi * 1;
result.value = myResult;
}
function kira7() {
var a = document.getElementById('result1').value;
var b = document.getElementById('result2').value;
var c = document.getElementById('result3').value;
var d = document.getElementById('result4').value;
var e = document.getElementById('result5').value;
var f = document.getElementById('result6').value;
var result = document.getElementById('jumlah_1A');
var myResult = a + b + c + d + e + f;
result.value = myResult;
}
</script>
But when i tried to run it, the total is not displaying as i want it to.
This is the output:
The total should be display at the "Jumlah Skor 1A"
Try using:
document.getElementById('jumlah_1A').innerHTML
i.e. document.getelementbyid('idname').innerHTML
As per my understanding 'jumlah_1A' is a div not a Input box. so use .innerHTML instead of .value
W3school Link:
http://www.w3schools.com/jsref/prop_html_innerhtml.asp
var a = parseInt(document.getElementById('result1').value);
var b = parseInt(document.getElementById('result2').value);
var c = parseInt(document.getElementById('result3').value);
var d = parseInt(document.getElementById('result4').value);
var e = parseInt(document.getElementById('result5').value);
var f = parseInt(document.getElementById('result6').value);
Convert all to integer before adding the values.
if jumlah_1A element is not a textbox then do
result.innerHTML = myResult;
I am trying to take part group of variables and add the information to a table. I have been able to add a table to encompass all the information displayed, however it does not place the information into a table that I want to see. Here is what the inital looks like (to new here to imput images): http://i.imgur.com/FxB8GMx.png - the red boxes is the information that I want divided into a table.
The information is pulled from a Sharepoint database using a soap function. I am including the place where all the variables are called:
function processResultOON(xData, status)
{
var result, subresult, outString="";
var ListTemp = new Array();
var ListUpdated = new Array();
var floatlat;
var floatlng;
var floatlatdist;
var floatlngdist;
var floatdist;
var floatdiststr;
var titletxt;
var biznametxt;
var addresstxt;
var citytxt;
var phonetxt;
var faxtxt;
var websitetxt;
var notestxt;
var cleanstr;
var ndx;
var placendx;
var swapped;
var loopcnt;
var maxndx;
var tempbizname;
var tempaddr;
var tempcity;
var temptitle;
var tempphone;
var tempfax;
var tempnotes;
var tempwebsite;
var tempdist;
var templat;
var templon;
var floattarglat;
var floattarglon;
var floatsamplat;
var floatsamplon;
var posel;
var vccsel;
var towltsel;
var towmedsel;
var towhvysel;
var lowboysel;
var dolliessel;
var motorcyclesel;
var tireltsel;
var tiremedsel;
var tirehvysel;
var winchsel;
var fuelsel;
var lockssel;
var locksmithsel;
var jumpsel;
var selOVN;
var notesstage;
var clearanceheight;
var currentinsertptr;
var currentlowdistptr;
var lowdistcheck;
var currentlowdist;
var checkptr;
var dropoutndx;
var title_ndx = 0;
var city_ndx = 1;
var businessname_ndx = 2;
var address_ndx = 3;
var phone_ndx = 4;
var fax_ndx = 5;
var notes_ndx = 6;
var lat_ndx = 7;
var lon_ndx = 8;
var website_ndx = 9;
var po_ndx = 10;
var vcc_ndx = 11;
var lowboy_ndx = 12;
var dollies_ndx = 13;
var motorcycle_ndx = 14;
var winch_ndx = 15;
var fuel_ndx = 16;
var locks_ndx = 17;
var locksmith_ndx = 18;
var jump_ndx = 19;
var OVN_ndx = 20;
var towlt_ndx = 21;
var towmed_ndx = 22;
var towhvy_ndx = 23;
var tirelt_ndx = 24;
var tiremed_ndx = 25;
var tirehvy_ndx = 26;
var clearance_ndx = 27;
var dist_ndx = 28;
var arrayndx;
var addtolist;
var addpin;
var d2 = new Date();
n2 = d2.getTime();
var count = 0;
try
{
if (status == "success" && result)
{
$(result).find("rs\\:data").each(function()
{
subresult = $(this);
$(subresult).find("z\\:row").each(function()
{
count++;
});
ListI = new Array(count);
for(var i=0;i<ListI.length;i++)
{
ListI[i] = new Array(29);
}
var d2a1 = new Date();
n2a1 = d2a1.getTime();
arrayndx = 0;
$(subresult).find("z\\:row").each(function()
{
ListI[arrayndx][title_ndx] = $(this).attr("ows_Title")
ListI[arrayndx][city_ndx] = $(this).attr("ows_City")
ListI[arrayndx][businessname_ndx] = $(this).attr("ows_Business_x0020_Name")
ListI[arrayndx][address_ndx] = $(this).attr("ows_Address")
ListI[arrayndx][phone_ndx] = $(this).attr("ows_Phone")
ListI[arrayndx][fax_ndx] = $(this).attr("ows_Fax")
ListI[arrayndx][notes_ndx] = $(this).attr("ows_Notes")
ListI[arrayndx][lat_ndx] = $(this).attr("ows_Lat")
ListI[arrayndx][lon_ndx] = $(this).attr("ows_Lon")
ListI[arrayndx][website_ndx] = $(this).attr("ows_Website")
ListI[arrayndx][po_ndx] = $(this).attr("ows_PO")
ListI[arrayndx][vcc_ndx] = $(this).attr("ows_VCC")
ListI[arrayndx][lowboy_ndx] = $(this).attr("ows_Lowboy")
ListI[arrayndx][dollies_ndx] = $(this).attr("ows_Dollies")
ListI[arrayndx][motorcycle_ndx] = $(this).attr("ows_Motorcycle")
ListI[arrayndx][winch_ndx] = $(this).attr("ows_Winch")
ListI[arrayndx][fuel_ndx] = $(this).attr("ows_Fuel")
ListI[arrayndx][locks_ndx] = $(this).attr("ows_Locks")
ListI[arrayndx][locksmith_ndx] = $(this).attr("ows_Locksmith")
ListI[arrayndx][jump_ndx] = $(this).attr("ows_Jump")
ListI[arrayndx][OVN_ndx] = $(this).attr("ows_OVN")
ListI[arrayndx][towlt_ndx] = $(this).attr("ows_Tow_x0020_light")
ListI[arrayndx][towmed_ndx] = $(this).attr("ows_Tow_x0020_medium")
ListI[arrayndx][towhvy_ndx] = $(this).attr("ows_Tow_x0020_heavy")
ListI[arrayndx][tirelt_ndx] = $(this).attr("ows_Tires_x0020_light")
ListI[arrayndx][tiremed_ndx] = $(this).attr("ows_Tires_x0020_medium")
ListI[arrayndx][tirehvy_ndx] = $(this).attr("ows_Tires_x0020_heavy")
ListI[arrayndx][clearance_ndx] = $(this).attr("ows_Clearance")
ListI[arrayndx][dist_ndx] = 0.0;
arrayndx++;
}
);
});
arrayndx = 0;
outheader="<tr>"
for (j in ListI[0])
{
outheader = outheader + "<th>" + j +"</th>";
}
outheader = outheader + "</tr>"
outString = outString + "<table>";
The information is then displayed to the show as it does in the image above using the below code. It is this information that I want to have put into a table. The question would be how do I put this information in a table without including the above unrelated information into the table?
posel = ListTemp[i][po_ndx];
vccsel = ListTemp[i][vcc_ndx];
towltsel = ListTemp[i][towlt_ndx];
towmedsel = ListTemp[i][towmed_ndx];
towhvysel = ListTemp[i][towhvy_ndx];
lowboysel = ListTemp[i][lowboy_ndx];
dolliessel = ListTemp[i][dollies_ndx];
motorcyclesel = ListTemp[i][motorcycle_ndx];
tireltsel = ListTemp[i][tirelt_ndx];
tiremedsel = ListTemp[i][tiremed_ndx];
tirehvysel = ListTemp[i][tirehvy_ndx];
winchsel = ListTemp[i][winch_ndx];
fuelsel = ListTemp[i][fuel_ndx];
lockssel = ListTemp[i][locks_ndx];
locksmithsel = ListTemp[i][locksmith_ndx];
jumpsel = ListTemp[i][jump_ndx];
selOVN = ListTemp[i][OVN_ndx];
clearanceheight = ListTemp[i][clearance_ndx];
notesstage = "";
if (posel == 1)
{
notesstage = notesstage + "<strong>PO </strong>";
}
if (vccsel == 1)
{
notesstage = notesstage + "VCC ";
}
if ((towltsel == 1) || (towmedsel == 1) || (towhvysel == 1))
{
notesstage = notesstage + "<b>Tow</b>: ";
if (towltsel == 1)
{
notesstage = notesstage + "<font color=#892EE4><b>LD </b></font>";
}
if (towmedsel == 1)
{
notesstage = notesstage + "<font color=#008080><b>MD </b></font>";
}
if (towhvysel == 1)
{
notesstage = notesstage + "<font color=#1FCB4A><b>HD </b></font>";
}
}
if (lowboysel == 1)
{
notesstage = notesstage + "Lowboy ";
}
if (dolliessel == 1)
{
notesstage = notesstage + "Dollies ";
}
if (motorcyclesel == 1)
{
notesstage = notesstage + "Motorcycle ";
}
if ((tireltsel == 1) || (tiremedsel == 1) || (tirehvysel == 1))
{
notesstage = notesstage + "<b>Tires</b> ";
if (tireltsel == 1)
{
notesstage = notesstage + "<font color=#892EE4><b>LD </b></font>";
}
if (tiremedsel == 1)
{
notesstage = notesstage + "<font color=#008080><b>MD </b></font>";
}
if (tirehvysel == 1)
{
notesstage = notesstage + "<font color=#1FCB4A><b>HD </b></font>";
}
}
I meet a trouble with a function. actually I need to make this function to perform a calculation on some text fields. When I worked on a single line no problems. But recently, someone asked to make a table with multiple lines (one line can be added dynamically) so, I do the following function so that it can not only duplicate line but id change all the fields concerned, so I add class to these fields. therefore I proceed as follows:
function clone(line) {
newLine = line.cloneNode(true);
line.parentNode.appendChild(newLine);
var tab = document.getElementsByClassName('libelle_debours')
var i = -1;
while (tab[++i]) {
tab[i].setAttribute("id", "_" + i);
};
var cab = document.getElementsByClassName('ht_no_tva')
var j = -1;
while (cab[++j]) {
cab[j].setAttribute("id", "_" + j);
};
var dab = document.getElementsByClassName('ht_tva')
var k = -1;
while (dab[++k]) {
dab[k].setAttribute("id", "_" + k);
};
var eab = document.getElementsByClassName('taux')
var l = -1;
while (eab[++l]) {
eab[l].setAttribute("id", "_" + l);
};
var fab = document.getElementsByClassName('tva')
var m = -1;
while (fab[++m]) {
fab[m].setAttribute("id", "_" + m);
};
}
function delRow() {
var current = window.event.srcElement;
//here we will delete the line
while ((current = current.parentElement) && current.tagName != "TR");
current.parentElement.removeChild(current);
}
The problem in fact is the second function that is used to make the calculation:
function calcdebours() {
var taux = document.getElementById('debours_taux_tva').value;
var ht_no_tva = document.getElementById('debours_montant_ht_no_tva').value;
var ht_tva = document.getElementById('debours_montant_ht_tva').value;
var tva = Math.round((((ht_tva) * (taux)) / 100) * 100) / 100;;
if (taux == '') {
taux = 0;
}
if (ht_no_tva == '') {
ht_no_tva = 0;
}
if (ht_tva == '') {
ht_tva = 0;
}
document.getElementById('debours_montant_tva').value = tva;
document.getElementById('debours_montant_ttc').value = (tva) + parseFloat(ht_tva) + parseFloat(ht_no_tva)
}
function
montant_debours() {
var ttc = document.getElementById('debours_montant_ttc').value;
var ttc2 = document.getElementById('debours_montant_ttc2').value;
if (ttc == '') {
var ttc = 0;
} else {
var ttc = document.getElementById('debours_montant_ttc').value;
}
if (ttc2 == '') {
var ttc2 = 0;
} else {
var ttc2 = document.getElementById('debours_montant_ttc2').value;
}
tx = parseFloat(ttc) + parseFloat(ttc2);
document.getElementById('ttc_cheque').value = Math.round(tx * 100) / 100;
}
As Id are not the same, do I have to create as many functions
there are lines?
Is it possible to fit a single function to process each line?
If so can you tell me how?
If I'm not mistaken you can use for loop and append increment to the end of element's id. Like this:
trs = document.getElementById('container Id').getElementsByTagName('tr');
For (var i = 1, i <= trs.length; i++)
{
var el = document.getElementById('debours_montant_ttc' + i);
}