User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 330,171 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,265 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 967 | Replies: 2
Reply
Join Date: Mar 2008
Posts: 3
Reputation: 1supergirl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
1supergirl 1supergirl is offline Offline
Newbie Poster

Question problem with my radio button validation js

  #1  
Mar 16th, 2008
I am a newbie to javascript and have written the following code to make sure that users have checked a radio button. It is set to work on submit. The form is generated by php and has approx 70 options; users may select one. I am not even sure if the script is being processed because if I test it by submitting without checking a button, the program tries to load the next page without passing a superglobal, and of course I get a php error: "Notice: Undefined index: item in C:\Program Files\EasyPHP 2.0b1\www\dap\subtypemenu.php on line 24". Is there something obvious in my code that is preventing it from executing? Thanks so much in advance for your help.


<script language='JavaScript 1.2'>

function submitIt(form)
	{
	myOption = -1
	for (i=0; i<document.prodsearch.item.length; i++)
	{
		if (document.prodsearch.item[i].checked)
		{
		myOption = i
		}
			if (myOption == -1)
			{
			alert("You must make a selection.")
			return false
			}
	return true
}</script> 
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: Bangalore, India
Posts: 327
Reputation: DangerDev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 31
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Whiz

Re: problem with my radio button validation js

  #2  
Mar 17th, 2008
hi,
Post your html code also or atleast describe what is prodsearch, and other var used in javaScript.
One more important thing, dont rely upon javaScript alone for validation, write server side equivalent code for that, as any one can alter your JavaScript code and send wrong info to server.
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
Reply With Quote  
Join Date: Mar 2008
Posts: 3
Reputation: 1supergirl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
1supergirl 1supergirl is offline Offline
Newbie Poster

Re: problem with my radio button validation js

  #3  
Mar 17th, 2008
Hi Danger,
Sorry about the omission; I am still new to this. I don't have html pages per se, they are generated on the fly by php. But here is the php that makes up prodsearch.php, and below that, I have added the main include, aniprod.php.
prodsearch.php
<?php

// Program name: prodsearch.php
// Description: Program displays list of radio buttons with products grouped by category from product database info.


//set variables and implement error handling
 	require "includes/db.php";

//establish connection to host and db
  $connection=mysql_connect($host,$user,$password)
  	or die("Couldn't connect to server");
  $db=mysql_select_db($database,$connection)
  	or die("Couldn't select database");

// retrieve html header
	include_once ('templates/header.tpl');

// retrieve nav bar
	include_once ('templates/nav.tpl');

// create form containing radio buttons
	   	echo "<form onSubmit='return submitIt(this)' action='subtypemenu.php' method='POST'>\n";
//pass values from aniloc
	include_once('includes/passvalue.php');


// create page structure
 	echo "<h1><b>Search for $_POST[prodserv]s for $_POST[pet]s </b></h1>
	 <p>Please Choose the $_POST[prodserv] You Are Shopping for from Following List:</p>\n";



//category bit

//get category from the database
$query = "SELECT * FROM category
		  WHERE CATEGORY_TYPE = '$_POST[prodserv]'
		  AND ANIMAL_NAME='$_POST[pet]'";
		//removed	  ORDER BY CATEGORY_NAME

$category=@mysql_query($query)
	or showerror();
		while ($row=@mysql_fetch_array($category))
		{
			echo "<p class='guide'>";
			print $row['CATEGORY_NAME'];
			$NOW=$row['CATEGORY_ABBREV'];
			echo "</p>";


	//get product bit
				include ('includes/aniprod.php');

		}   //looping to get other categories

//fence footnote
include('includes/fenceftn.php');


//submit

 echo "<p><input type='submit' value='Select from $_POST[prodserv]s'></form>\n";

// retrieve footer
	include_once ('templates/footer.tpl');
?>
aniprod.php
<?php
//Program: aniprod.php
//Description: this program selects only products that relate to a specific category abbrev to populate that category for prodsearch module


//query db
	 $query="SELECT * FROM product
	  	WHERE CATEGORY_ABBREV='$NOW'
	  	AND ANIMAL_NAME='$_POST[pet]'";
		//removed  	ORDER BY PRODUCT_NAME

	   $result=@mysql_query($query)
	or showerror();

	   	while ($row=@mysql_fetch_array($result))
	   	{

	 		extract($row);
	 		echo "<input type='radio' name='item' value='$PRODUCT_ABBREV'><b>$PRODUCT_NAME</b>\n";

	 		//fence footnote symbol
	 			include('includes/fenceftncondition.php');

	 		echo "<input type='hidden' name='issubtype' value='$ISSUBTYPE'>";

	 		echo "<br>\n";
	   	} 	 // looping to get other products under the same category




?>

Thank you so much; I appreciate you looking at my code.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:24 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC