Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post

    Arrow pass a variable to a function in innerHTML

    Code:
    				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

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what is the error you are getting?

    (posting more code here could help)
    rm -f /

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    Code:
    /*
    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

  • #4
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    Code:
    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

  • #5
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)
    rm -f /

  • #6
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •