Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript "is not a function" error

Posted on 2008-10-11
5
Medium Priority
?
1,817 Views
Last Modified: 2012-06-27
Hi,

I have two radio buttons, that I want to toggle whether a textbox is disabled or not. I have then running an onChange event to go to the cashOrCheck() function (code is attached). However, firebug keeps saying that "cashOrCheck is not a function", and I just can't figure out what the problem is. I have a feeling that it's a very simple answer...but it just needs a fresh set of eyes. The javascript function is in an external file, and the other functions from that file work fine and are all closed and everything.

Any help will be appreciated. Thanks!
<form action='payments.php' method='post'>
<input type='hidden' name='submitPayment' value='$paymentID'>
Payment Method:<input type='radio' name='cashOrCheck' value='cash' id='cashCheck' onChange=\"cashOrCheck()\" />Cash&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='cashOrCheck' value='check' id='cashCheck' onChange=\"cashOrCheck()\" />Check<br />
Check Number:<input type='text' name='checkNum' id='checkNum'>
<br /><input type='submit' value='Submit'>
</form>";
 
 
function cashOrCheck()
{
var button = document.getElementById('cashCheck');
if (button.value == 'cash')
document.getElementById('checkNum').disabled = true;
else
document.getElementById('checkNum').disabled = false;
}

Open in new window

0
Comment
Question by:bkaneweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Assisted Solution

by:Davejk88
Davejk88 earned 1000 total points
ID: 22696090
Try it this way:

var cashOrCheck = function() {
    var button = document.getElementById('cashCheck');
    if (button.value == 'cash') {
        document.getElementById('checkNum').disabled = true;
    } else {
        document.getElementById('checkNum').disabled = false;
    }
}

Open in new window

0
 

Author Comment

by:bkaneweb
ID: 22696108
Thanks for the reply, but that solution still gives the same error. I've attached the complete javascript functinos page, maybe there was an error in one of the others that I'm missing that could be leading to this error...

I think all of the braces are closed, and the script is being imported OK...

thanks again...

function ajaxFunction(use, meeting){
	var ajaxRequest;  // The variable that makes Ajax possible!
	var meetingID = meeting;
	var page = use;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("myDECA is not supported on this browser. Sorry!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('sidebarContent');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			var el = $('sidebar');
			var myEffect = new Fx.Tween(el);
			// We change the background-color of the element
			myEffect.start('background-color', '#ecddbe', '#fff8f0');
		}
	}
	ajaxRequest.open("GET", "sidebar.php?sidebar=" + meetingID + "&page=" + page, true);
	ajaxRequest.send(null); 
}
function setRowSelected(id)
{
 	var element = document.getElementById(id);
	element.style.background='#f1e6d8'
}
function setRowUnselected(id)
{
 	var element = document.getElementById(id);
	element.style.background=''
}
function ActivateAMC()
{
 	var box1 = document.getElementById('ptvalue');
 	var box2 = document.getElementById('category');
		box1.disabled = false;
		box1.style.color='';
		box2.disabled = false;
		box2.style.color='';
}
function DeactivateAMC()
{
 	var box1 = document.getElementById('ptvalue');
 	var box2 = document.getElementById('category');
		box1.disabled = true;
		box1.style.color='#dfdfdf';
		box2.disabled = true;
		box2.style.color='#dfdfdf';
}
function checkAll(id){
   	var f = document.getElementById(id);
   	var inputs = f.getElementsByTagName("input");
   	for(var t = 0;t < inputs.length;t++){
     	if(inputs[t].type == "checkbox")
       		inputs[t].checked = true;
   	}
}
function uncheckAll(id){
   	var f = document.getElementById(id);
   	var inputs = f.getElementsByTagName("input");
  	 for(var t = 0;t < inputs.length;t++){
     	if(inputs[t].type == "checkbox")
       		inputs[t].checked = false;
   	}
}
function invertAll(){
	var f = document.getElementById('members');
	var inputs = f.getElementsByTagName('input');
	for (var t = 0; t < inputs.length; t++) {
		if (inputs[t].type == 'checkbox') {
			inputs[t].checked = !inputs[t].checked;
			alert(inputs[t].value);
		}
	}
	invertAllRows();
}
function invertAllRows(){
	var f = document.getElementById('memberList');
	var rows = f.getElementsByTagName('tr');
	for (var t = 0; t < rows.length; t++) {
		if (rows[t].style.background=='#f1e6d8')
			rows[t].style.background='';
		else
			rows[t].style.background='#f1e6d8';
	}
}
 
//REGISTRATION FORM
 
function checkUsernameForLength(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > 5) {
		fieldset.className = "welldone";
	}
	else {
		fieldset.className = "";
	}
}
 
function checkPassword(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length == 4 || txt.length == 5) {
		fieldset.className = "kindagood";
	} else if (txt.length > 5) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}
function checkConf(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	var origPass = document.getElementById('password').value;
	if (txt == origPass && txt.length > 0) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}
 
function checkForLetters(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > 0) {
		fieldset.className = "welldone";
	}
	else {
		fieldset.className = "";
	}
}
 
function checkEmail(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt)) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}
 
function checkGrade(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	if (whatYouTyped.selectedIndex != 0) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}
 
 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
 
function prepareInputsForHints() {
	
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i<inputs.length; i++){
    inputs[i].onfocus = function () {
      this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
    }
    inputs[i].onblur = function () {
      this.parentNode.getElementsByTagName("span")[0].style.display = "none";
    }
  }
  document.getElementById('firstName').focus();
  document.getElementById('firstName').parentNode.getElementsByTagName("span")[0].style.display = "inline";
}
 
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}
 
var cashOrCheck = function() {
    var button = document.getElementById('cashCheck');
    if (button.value == 'cash') {
        document.getElementById('checkNum').disabled = true;
    } else {
        document.getElementById('checkNum').disabled = false;
    }
}

Open in new window

0
 
LVL 2

Accepted Solution

by:
Davejk88 earned 1000 total points
ID: 22696152
Putting that code through JSLint returns quite a few errors - try fixing those, and see if it works afterwards. The issue is probably coming from the cashOrCheck function being defined at the end of the file, which will never be reached since the interpreter will stop reading a file when it hits an error.
0
 

Author Comment

by:bkaneweb
ID: 22696195
Thanks for the reply...

while that did find a bunch of errors that I had to fix, that wasn't the cause of it. After becoming desperate and trying everything with the code, I decided to change the name and ID of the radio button. For some reason, I recieved that error when the word 'Check' was in the ID name...perhaps that's a javascript key word or something...

Well, thanks for your help, and i do appreciate it...
0
 

Author Closing Comment

by:bkaneweb
ID: 31505379
Thanks for your help!
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question