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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Required error 1

Status
Not open for further replies.

Billybong007

IS-IT--Management
Mar 21, 2007
10
GB
Hi,

I've been hacking away at a script to determine if a radio button value is in a list of numbers

Using support from other in the ASP section of the site and from other tutorials on the net and came up with :

Code:
<script>
function whichButton() {
var group1Checked 
var myString = "11,12,3,22,18,19,55";
var mySplitResult = myString.split(",");

for(i = 0; i < mySplitResult.length; i++){
	document.write("<br /> Element " + i + " = " + mySplitResult[i]); 
}

	for (var i=0; i<document.survey.optSecenek.length; i++) {
	
		if (document.survey.optSecenek[i].checked) {
		group1Checked = document.survey.optSecenek[i].value
		}
		}
			
	if(!group1Checked) == (!mySplitResult){ //if group1Checked does not equal null
	alert("Found You")
	}
	else{
	alert("Not found")
	} 

}


</script>

I can get the scripts working seperately i.e. I have learnt now how to split the variable and display the results.

I have also been able to determine the value of a dynamic number of radio buttons and display the value - so I added the two scripts together with a few edits to determine if (!group1Checked) == (!mySplitResult)but it fails with a warning of "Object required"

Any ideas what it's looking for ?

Thanks for your help

Billybong
 
If you document.write something to a page that is completed, you will most likely destroy everything else on the page. That means that your survey form will no longer exist on the page.

If you want to see the numbers on the page, why aren't you writing them to the page when the page is loading?

Also, you can create the array of numbers without making the string and splitting it:
Code:
var mySplitResult = [11,12,3,22,18,19,55];

Lee

Lee
 
thanks Lee.

I was doing a document.write to see if the script was getting that far, I'll take it out and see what happens.

will creating an array of numbers without making the string and splitting it allow me to have a variable (the radio button value) check to see if it is one of the numbers in that array ?

sorry for the novice questions - I've only ever learnt javascript by playing around
 
Something like this:
Code:
for (var i=0; i<document.survey.optSecenek.length; i++)
  {
  if (document.survey.optSecenek[i].checked)
    {
    group1Checked = document.survey.optSecenek[i].value;
    }
  }

for (i = 0; i<mySplitResult.length;i++)
  {
  if(group1Checked == mySplitResult[i])
    {
    alert("Found You");
    return;
    }
  }
alert("Not found");
}

Lee
 
Thanks Lee - it worked a treat

here's the full code for anyone interested :

Code:
<script>
function whichButton() {
var group1Checked;
var myString = "155,12,3,22,18,19,55"; // set the option IDs that need checking
var mySplitResult = myString.split(","); // Split the Option IDs into variables

for (var i=0; i<document.survey.optSecenek.length; i++) // Determine how many radio buttons are in the form
  {
  if (document.survey.optSecenek[i].checked) // Check the value of the set radio button
    {
    group1Checked = document.survey.optSecenek[i].value;  // set the var group1Checked to the value of the Radio button
    }
  }

for(i = 0; i < mySplitResult.length; i++) // Determine the how many variables there are in myString
  {
   if(group1Checked == mySplitResult[i]) // Check if Radio button value = a number in myString
   {
    alert("Found You"); // If found do this, else do nothing.
    return;
    }
  }
}  

</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top