Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

testing variable passed in prob... 1

Status
Not open for further replies.

adamroof

Programmer
Joined
Nov 5, 2003
Messages
1,107
Location
US
i tried with single quotes, double quotes, no quotes, how do i check to see which textbox started the function.

the last else is returning true at all times

Code:
 - onKeyUp("dothis(this,frmConfig.txtODMM);")
 - onKeyUp("dothis(this,frmConfig.txtIDMM);")
 - onKeyUp("dothis(this,frmConfig.txtThickMM);")

function dothis(field,destfield)	       
                if (destfield == "frmConfig.txtODMM") {
	            //document.getElementById('lblODMeas').style.visibility = 'hidden';
	            document.getElementById('lblODMeas').innerHTML = "I";		        
	        }
	        else {
	        if (destfield == "frmConfig.txtIDMM"){
	            //document.getElementById('lblIDMeas').style.visibility = 'hidden';
	            document.getElementById('lblIDMeas').innerHTML = "I";	  	        
	        } 
	        else {
	            //document.getElementById('lblThickMeas').style.visibility = 'hidden';
	            document.getElementById('lblThickMeas').innerHTML = "I";		        
	        };
	        };
 
elaborate on this:

- onKeyUp("dothis(this,frmConfig.txtODMM);")
- onKeyUp("dothis(this,frmConfig.txtIDMM);")
- onKeyUp("dothis(this,frmConfig.txtThickMM);")

how are you making these assignments?



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
those are textbox events...

<asp:TextBox ID="txtODInches" onKeyUp="dothis(this,frmConfig.txtODMM);" TabIndex="2" runat="server" CssClass="tbSearch" name="txtODInches" />
 
You pass two values field and destfield.
Are you saying that destfield is the name of the field you are calling FROM? Because the first parameter field is the object of the field you called from making the second value redundant.

You can do this:
if (field.id == "frmConfig.txtODMM") .....

If you want to compare against the TEXT of the destfield value then you have to pass it as text, not as an object like this:
onKeyUp("dothis(this,'frmConfig.txtODMM');")

Except that the onKeyUp does not look right to me. Are you doing this from within a form field as an event? If so then it should be like this:
onKeyUp="dothis(this,'frmConfig.txtODMM');"




Stamp out, eliminate and abolish redundancy!
 
but, in reality, if you're naming that parameter "destfield" (short, i'm sure, for "destination field"), then why not do something like this:

Code:
 - onKeyUp("dothis(this,frmConfig.txtODMM);")
 - onKeyUp("dothis(this,'lblIDMeas');")
 - onKeyUp("dothis(this,'lblODMeas');")
 - onKeyUp("dothis(this,'lblThickMeas');")

Code:
function dothis(field,destfield) {
    document.getElementById(destfield).innerHTML = 'I';
}



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
ok fine! i was trying to be concise, however here is the whole function!

ill try the destfield.name or field.id

thanks for stickin with me...

Code:
function dothis(field,destfield)
{
    var mmconv = "25.4";
	var valid = "0123456789.";
	var isValid = true;
	var temp;
	for (var i=0; i < field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
		{
			isValid = false;
		}
	}
	if(isValid == false)
	{
		alert("Invalid Entry! Only numeric values are accepted in this field.");
		var mynewval = field.value;
		mynewval = mynewval.slice(0,mynewval.length-1)
		field.value = mynewval;
	} 
	else
	{
	if (field.value.length < 1)
	{
		field.style.color='black';
	    field.style.backgroundColor='white';
	    destfield.style.color='black';
	    destfield.style.backgroundColor='white';
	    destfield.value = "";
	}
	else
	{
	var myval = (field.value * mmconv);
	myval = myval.toFixed(3);
	    	field.style.color='white';
	    	field.style.backgroundColor='gray';
	        destfield.style.color='black';
	        destfield.style.backgroundColor='white';
	        if (destfield == "frmConfig.txtODMM") {
	            //document.getElementById('lblODMeas').style.visibility = 'hidden';
	            document.getElementById('lblODMeas').innerHTML = "I";		        
	        }
	        else {
	        if (destfield == "frmConfig.txtIDMM"){
	            //document.getElementById('lblIDMeas').style.visibility = 'hidden';
	            document.getElementById('lblIDMeas').innerHTML = "I";	  	        
	        } 
	        else {
	            //document.getElementById('lblThickMeas').style.visibility = 'hidden';
	            document.getElementById('lblThickMeas').innerHTML = "I";		        
	        };
	        };
	destfield.value=myval
	};    
    };        
}
 
still, you're passing in an object, such as frmConfig.txtODMM, which I suppose is a form field.

later on in the code, you're testing against a string, "frmConfig.txtODMM".

the two are not the same.



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
This works! still open to "Stamp out, eliminate and abolish redundancy!" nightowl
Code:
	var myval = (field.value * mmconv);
	myval = myval.toFixed(3);
	    	field.style.color='white';
	    	field.style.backgroundColor='gray';
	        destfield.style.color='black';
	        destfield.style.backgroundColor='white';
	        if (destfield.name == "txtODMM") {
	            document.getElementById('lblODMeas').innerHTML = "I";		        
	        }
	        else {
	        if (destfield.name == "txtIDMM"){
	            document.getElementById('lblIDMeas').innerHTML = "I";	  	        
	        } 
	        else {
	            document.getElementById('lblThickMeas').innerHTML = "I";		        
	        };
	        };
	    destfield.value=myval
	};    
    };
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top