Solved

Javascript "is not a function" error

Posted on 2008-10-11
5
1,801 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
  • 3
  • 2
5 Comments
 
LVL 2

Assisted Solution

by:Davejk88
Davejk88 earned 250 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 250 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Form submit issue 11 54
jQuery Animate Left Right 2 44
Detecting robots? 5 35
Hovering effect 9 29
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now