0

hi,

I am creating a script where i have 4 combo box collecting the value from database. and i want if some one select the other option from the combo box the text box is enable.

and all 4 combo box have an alternative text box and i want same feature.

when page is load 1st time by default all the text box should
disable.
and as we select the other option from combo boxes the page reload
with appropriate enabled text box.

the problem is when i select any option other then 'others'
it works fine but when i select 'other' option instead of open the text box it still disable.
I cant understand the problem....

thats my code of javascript:

function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value; 
self.location='create_own_inventory.php?cat=' + val ;
}
function def()
{
document.f1.newcat.disabled=true;
document.f1.newsubcat1.disabled=true;
document.f1.newsubcat2.disabled=true;
document.f1.newsubcat3.disabled=true;
}

function makeChoice()

{
 var val = 0;
document.f1.newcat.disabled=true;
document.f1.newsubcat1.disabled=true;
document.f1.newsubcat2.disabled=true;
document.f1.newsubcat3.disabled=true;

for( i = 0; i < document.f1.cat.length; i++ )
{
if( document.f1.cat.options[i].selected == true )
{
val = document.f1.cat.options[i].value;
if(val=='other')
{
document.f1.newcat.disabled=false;
document.f1.newcat.focus();
}
}
}
}

my php combo box is:

echo "&nbsp;&nbsp;&nbsp;<select name='cat' onchange=\"reload(this.form)\" onclick=\"makeChoice()\"><option value=''>Main Catagory</option>";
while($noticia2 = mysql_fetch_array($quer2)) 
	{ 
    if($noticia2['Top_Level_Category']==@$cat)
		{
		echo "<option selected value='$noticia2[Top_Level_Category]'>$noticia2[Top_Level_Category]</option>"."<BR>";
	}
else
	{
	echo  "<option value='$noticia2[Top_Level_Category]'>$noticia2[Top_Level_Category]</option>";
	}
   }
echo  "<option value='other'>Others</option>";
echo "</select>&nbsp;&nbsp; OR Create Own Main Catagory";
echo '<INPUT TYPE="text" NAME="newcat"><BR><BR>';

function def() i am using in body onload
event using

<body onload="def();">

plz help me what is my problem???
in that code in javascript

2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by sandipan.rcciit
0

Could you post the HTML from a View Source on your browser? I can't see what your select options look like from the server code.

0

Could you post the HTML from a View Source on your browser? I can't see what your select options look like from the server code.

I send my code with database structure.
2 files r php file and data1.txt is database file.
plz create your own connection string of php mysql
plz help me.

Attachments
<?php
session_start();
$xyz=$_SESSION['username'];
$var1=$_GET['var'];
$var2=$_GET['var2'];
?>
<?php
$cat=$_POST["cat"];
$subcat=$_POST["subcat"];
$subcat4=$_POST["subcat4"];
$subcat5=$_POST["subcat5"];
$newcat=$_POST["newcat"];
$newsubcat1=$_POST["newsubcat1"];
$newsubcat2=$_POST["newsubcat2"];
$newsubcat3=$_POST["newsubcat3"];
if($cat=="")
{
$top_cat=$newcat;
}
else
{
$top_cat=$cat;
}

if($subcat=="")
{
$top_scat1=$newsubcat1;
}
else
{
$top_scat1=$subcat;
}

if($subcat4=="")
{
$top_scat2=$newsubcat2;
}
else
{
$top_scat2=$subcat4;
}

if($subcat5=="")
{
$top_scat3=$newsubcat3;
}
else
{
$top_scat3=$subcat5;
}

if($top_scat3=="")
{
$s3="None";
}
else
{
$s3=$top_scat3;
}

$isbn=$_POST['isbn'];
$isbn13=$_POST['isbn13'];
$title_short=$_POST['title_short'];
$authors_name=$_POST['authors_name'];
$title_long=$_POST['title_long'];
$publisher_name=$_POST['publisher_name'];
$cost=$_POST['cost'];
$cost_currency=$_POST['cost_currency'];
$book_condition=$_POST['book_condition'];
$condition_note=$_POST['condition_note'];
$quantity=$_POST['quantity'];


if(!empty($_POST)){
          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
			  if($imagename=="")
			  {
                
			    $photo_id="bookimg/default.jpg";
			  }
			  else
			  {
			  $imagename=str_replace(" ","_",$imagename);
              $source = $_FILES['new_image']['tmp_name'];
              $target = "bookimg/".$imagename;
              move_uploaded_file($source, $target);
              
              $imagepath = $imagename;
              $save = "bookimg/" . $imagepath; //This is the new file you saving
              $file = "bookimg/" . $imagepath; //This is the original file

              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 90; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 

                         
			$photo_id="bookimg/".$imagepath;
			  }

include 'mysql-connect.php';

$cat="";
$query11 = mysql_query("SELECT distinct Category_Code from  books_category_master WHERE Sub_Level_3='$s3' AND Sub_Level_2='$top_scat2' AND Sub_Level_1='$top_scat1' AND Top_Level_Category='$top_cat'");
$res=mysql_num_rows($query11);
if($res==1)
{
$subcat11=mysql_fetch_array($query11);
 $cat_code=$subcat11['Category_Code'];
 $cat=$cat_code;
}
else
{
$cat_code = substr(md5(time()), 0, 4);
 //echo "Your catagory code is:-" $cat_code;
 mysql_query("INSERT INTO 
 books_category_master(cat_id,Top_Level_Category,Sub_Level_1,Sub_Level_2,Sub_Level_3,Category_Code )
 values(23330,'$top_cat','$top_scat1','$top_scat2','$s3','$cat_code')");

$cat=$cat_code;
}

$checkcode = mysql_query("SELECT * FROM books_category_master WHERE Category_Code='$cat'");
      $row = mysql_num_rows($checkcode);
 if($row==0)
 {
 echo'Sorry Seller its not a valid Category Code,Try again with Valid one';
 }
else
{
	$result = mysql_query("INSERT INTO tmp_single_record (ISBN,ISBN13,Title_Short,Title_Long,Authors_Name,Publisher,Category_Code,book_condition,condition_note,price,cur,quantity,photo_id,username) VALUES('$isbn','$isbn13','$title_short','$title_long','$authors_name','$publisher_name','$cat','$book_condition','$condition_note','$cost','$cost_currency','$quantity','$photo_id','$xyz')") or die(mysql_error());

$msg3="1 record uploaded successfully for Verification"; 	 
         	 
header("Location:upload_items.php?var=$msg3");
          }
        }
			
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #000000;
}
.style1 {color: #000000}
.style4 {font-family: Arial, Helvetica, sans-serif; font-size: 14px; }
.style17 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 16px;
	font-weight: bold;
}
-->
</style>
<SCRIPT language=JavaScript>

function Form1_Validator(theForm)
{

if (theForm.isbn.value == "")
{
alert("Please enter isbn no of the book if you dont have, write N.A .");
theForm.isbn.focus();
return (false);
}
if (theForm.isbn13.value == "")
{
alert("Please enter isbn13 no of the book if you dont have, write N.A .");
theForm.isbn13.focus();
return (false);
}
if (theForm.authors_name.value == "")
{
alert("Please enter Name of the author .");
theForm.authors_name.focus();
return (false);
}
if (theForm.title_long.value == "")
{
alert("Please enter some punch line of the book .");
theForm.title_long.focus();
return (false);
}
if (theForm.publisher_name.value == "")
{
alert("Please enter publisher name of the book .");
theForm.publisher_name.focus();
return (false);
}
if (theForm.cost.value == "")
{
alert("Please enter cost of the book .");
theForm.cost.focus();
return (false);
}
if (theForm.condition_note.value == "")
{
alert("Please enter the current condition about the book .");
theForm.condition_note.focus();
return (false);
}
if (theForm.quantity.value == "")
{
alert("Please enter how many books you have? .");
theForm.quantity.focus();
return (false);
}
}
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value; 
self.location='create_own_inventory.php?cat=' + val ;
}
function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value; 
var val2=form.subcat.options[form.subcat.options.selectedIndex].value; 

self.location='create_own_inventory.php?cat=' + val + '&cat3=' + val2 ;
}

function reload4(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value; 
var val2=form.subcat.options[form.subcat.options.selectedIndex].value; 
var val3=form.subcat4.options[form.subcat4.options.selectedIndex].value; 

self.location='create_own_inventory?cat=' + val + '&cat3=' + val2 + '&cat4=' + val3 ;
}

</script>

</head>
<div id="container">
  <table width="1240" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="134" valign="baseline" background="images/header.jpg">&nbsp;</td>
    </tr>
  </table>
  <div id="headimg">
  <div class="text">
    <table width="200" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="82" rowspan="2"><div align="center"><img src="images/home.gif" width="63" height="57" /></div></td>
        <td width="52" rowspan="2" valign="bottom"><table width="52" height="22" border="0">
          <tr>
            <td width="46" class="style1">Home</td>
          </tr>
        </table></td>
        <td width="66" height="28" valign="bottom">&nbsp;</td>
      </tr>
      <tr>
        <td height="33">&nbsp;</td>
      </tr>
    </table>
  </div>
  <div class="search">
    <table width="334" height="26" border="0" align="right" cellpadding="0" cellspacing="0">
      <tr>
        <td width="145" height="26" valign="top">&nbsp;</td>
        <td width="104">Your Account &nbsp;|</td>
        <td width="85">Help</td>
      </tr>
    </table>
    
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="textfield" type="text" id="textfield" size="70" />
    Search  </div>
  <div class="upmenu">
    <table width="1031" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="10" align="left" valign="top"><img src="images/stripleft.jpg" width="10" height="31" /></td>
        <td width="1010" height="31" background="images/striprepeat.jpg"><table width="506" border="0" align="left" cellpadding="0" cellspacing="0">
          <tr>
            <td width="10">&nbsp;</td>
            <td width="109" class="style1"><div align="center" class="style4">Category</div></td>
            <td width="10" class="style1"><div align="center" class="style4"><img src="images/line.jpg" width="1" height="24" /></div></td>
            <td width="124" class="style1"><div align="center" class="style4">Used Books</div></td>
            <td width="11" class="style1"><div align="center" class="style4"><img src="images/line.jpg" width="1" height="24" /></div></td>
            <td width="150" class="style1"><div align="center" class="style4">Advance Search</div></td>
            <td width="10" class="style1"><div align="center"><span class="style4"><img src="images/line.jpg" width="1" height="24" /></span></div></td>
            <td width="100" class="style1"><div align="center" class="style4">Sellers</div></td>
          </tr>
        </table></td>
        <td width="11" height="31" align="left" valign="top"><img src="images/stripright.jpg" width="8" height="31" /></td>
      </tr>
    </table>
  </div>
  </div>
  
  <br />
  <table width="698" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="759"><table width="604" border="0" align="center" cellpadding="3" cellspacing="3">
          <tr>
            <td class="heading">Personalize &gt; Seller  Information</td>
          </tr>
      </table></td>
    </tr>
  </table>
  <br />
  <table width="1150" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td><div id="box2">
        <table width="1100" border="0" align="center" cellpadding="0" cellspacing="0">
          
          <tr>
            <td colspan="2" bgcolor="#FEEBA9" class="tdcolour"><div align="center" class="style17">Inse
-- phpMyAdmin SQL Dump
-- version 2.11.0
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 01, 2010 at 05:03 AM
-- Server version: 5.0.45
-- PHP Version: 5.2.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `acc`
--

-- --------------------------------------------------------

--
-- Table structure for table `books_category_master`
--

CREATE TABLE `books_category_master` (
  `cat_id` int(4) NOT NULL,
  `Top_Level_Category` varchar(50) collate ascii_bin NOT NULL,
  `Sub_Level_1` varchar(50) collate ascii_bin NOT NULL,
  `Sub_Level_2` varchar(50) collate ascii_bin NOT NULL,
  `Sub_Level_3` varchar(50) collate ascii_bin NOT NULL,
  `Category_Code` varchar(10) collate ascii_bin NOT NULL,
  UNIQUE KEY `Category_Code` (`Category_Code`)
) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin COMMENT='Category Master';

--
-- Dumping data for table `books_category_master`
--

INSERT INTO `books_category_master` (`cat_id`, `Top_Level_Category`, `Sub_Level_1`, `Sub_Level_2`, `Sub_Level_3`, `Category_Code`) VALUES
(23330, 'Science', 'Physics', 'Nuclear Physics', 'None', '6602');
0

I send my code with database structure.
2 files r php file and data1.txt is database file.
plz create your own connection string of php mysql
plz help me.

Hi frnd i am waiting for your reply and already sent my file and database structure.

in the current php file i dont use none of the javascript which i was mentioned above.plz give me the way and procedure to use those one or any other to achieve my goal...
thank you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.