...

View Full Version : pass a variable to a function in innerHTML



crmpicco
10-19-2005, 12:51 PM
seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
"title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
"class='selects' size='5' onBlur='concatSeats(this.value,"+passNo+",this.id);' onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";



How can i pass a variable called 'pass' to the function concatSeats?
this works for 3 paramaters concatSeats(this.value,"+passNo+",this.id), but when i try
concatSeats(this.value,"+passNo+",this.id,"+pass+") i get a error.

Picco

rm-f
10-19-2005, 03:27 PM
what is the error you are getting?

(posting more code here could help)

crmpicco
10-19-2005, 04:12 PM
/*
FUNCTION NAME: specifySeat
Hide the 'Seat' image and build a text box for the cell
for user to enter seat number into
*/
function specifySeat(passType,passNo,seg,seatReq)
{

var doc = document.form;
var df = document.forms["form"];

var noa = doc.noa.value;
var noc = doc.noc.value;


if (passType == "ADT")
{
var passagier = "Adult";
pass = "AD";
}
else if (passType == "CHD")
{
var passagier = "Child";
pass = "CH";
}

alert("pass = " + pass);

// If the user selected to specify their own seat
if (seatReq == "specify_seat")
{
for(s=0; s<=seg; s++)
{
if (document.getElementById("FL"+s) != null)
{
var seat_zelle = document.getElementById("FL"+s);
//seat_zelle.style.visibility = "hidden";

if (document.getElementById("seat_img"+s) != null)
{
var seat_img = document.getElementById("seat_img"+s);
seat_img.style.visibility = "hidden";
}
//var temp = "TEST";
alert("pass = " + pass);
temp = pass;
alert("temp = " + temp);
seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
"title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
"class='selects' size='5' onBlur='concatSeats(this.value,"+passNo+",this.id,"+pass+");' onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";
//seat_zelle.onClick = "return test();";
bOpenWin = false;
var selectedSeats = true;

//alert("CHanged selectedSeats = " + selectedSeats);
}
}
}
}


entire function

crmpicco
10-19-2005, 04:15 PM
var temp = "AD";
seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
"title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
"class='selects' size='5' onBlur='concatSeats(this.value,"+passNo+","+temp+",this.id);' onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";
//seat_zelle.onClick = "return test();";
bOpenWin = false;
var selectedSeats = true;


this code gives me 'AD' is undefined at line 1

rm-f
10-20-2005, 05:33 PM
If you are getting error on entire function you have a syntax problem somewhere.


this code gives me 'AD' is undefined at line 1
points to a missed double-quote (probably)

Pyth007
10-21-2005, 12:58 PM
Actually, rm-f was sort-of correct... As you have it, you are passing in:
"+text+"
Since you have text="AD", when it gets substituted in you get:
"+"AD"+"
which places AD outside of quotes! Thus it thinks that AD is a variable and it cannot find what AD refers to. You want to rather pass in:
"+"+text+"+" so that when the substitution for text is made you get "+"+"AD"+"+" (the red are all inside quotes; the black are variables or +'s concating everything together)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum