Need some javascript help

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Vash the Stampede
Forum Newbie
Posts: 7
Joined: Tue Mar 30, 2004 6:15 pm

Need some javascript help

Post by Vash the Stampede »

I am kinda new to javascript and I need a little help with the focus() command. What I am trying to do is have on the fly error checking in my script and I know I am doing something wrong I just don't know what it is.

this is the text field code:

Code: Select all

<input class='tbox' type='text'  id='cf_tickerWidth' name='cf_tickerWidth' value='100' size='3' maxlength='3'onBlur='checkData(this)' />


and this is my javascript:

Code: Select all

function checkData(dataName){
	  
	  switch(dataName.name){
	    case 'cf_tickerWidth':
	    	try {
	    		if (!dataName.value){
	    			throw new Error('The Ticker Width cannot be blank.');
		    	} else if (dataName.value <= 0 || dataName.value > 100){
				  	throw new Error('The Ticker Width needs to be between 1 and 100.');
				}
			}
			
			catch (errMsg){
	   			alert(errMsg.message)
	   			dataName.name.focus();
	    		        dataName.name.select();
			}
	    break
	    
	    default:
	    	alert('It didn\'t work ' + dataName.name + ' ' + dataName.value);
		}

	  
	}


The alert box will display but it will not focus on the field or select the data within. The error I get in my javascript console is "dataName.name.focus is on a function" .

I have tried putting dataName.name into a var (i.e. var testName = dataName.name) and use it that way with no luck. Soooo what am I doing wrong? Thanks :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

lose the .name part of the expression for both focus() and select()
User avatar
Vash the Stampede
Forum Newbie
Posts: 7
Joined: Tue Mar 30, 2004 6:15 pm

Post by Vash the Stampede »

Well when I tried that at first it didn't seem to work, so as I sat here and thought as I opened internet explorer and tried it............... :lol:

I should have guessed, it works in IE but it doesn't appear to work in mozilla. Oh well. Thanks for the help.
Post Reply