/    Sign up×
Community /Pin to ProfileBookmark

Hi There,

At the moment I have the script below and a seperate page, but would like to include it into my main page. The problem I have is when you select a value from the dropdown, the page submits to the value set in the main pages for value. Please can some one tell what I need to change inorder to have the script not submit the value that the main forms action is set to. Is there a way that I can set a different value for the action of the script and then add an if statemnt to the main form?

<? require (“config.php”); ?>
<?
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
$db = mysql_select_db($dbname);
?>
<head>

<title>Coleshill Biz</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>

<link rel=stylesheet type=”text/css” href=”../css/cb.css”>

</head>
<body bgcolor=”#DAE4DA”>

<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td colspan=”2″ ><div align=”center” class=”hgb”>
Please select the Category and Sub Category you
would like your listing to appear in.
</div></td>
</tr>

<tr>
<td align=”center”>&nbsp;</td>
</tr>
<tr>

<td align=”center”><form name=”cat_select” action=”<? echo “$PHP_SELF”; ?>” method=”POST”>
<?

//db connections

$cat = $_POST[‘cat’]; <a href=”add_confirm.php”>add_confirm.php</a>
$sub_cat = $_
POST[‘sub_cat’];

if(!isSet($cat))
{
$result = mysql_query(“select * from category”);
echo “<select name=”cat” class=”formtextbox” onChange=”javascript:document.cat_select.submit();”>”;
echo ” <option selected>Select Category</option>”;

while ($row = mysql_fetch_array($result))
{
echo “<option value=”.$row[‘cat_id’];
echo “>”.$row[‘cat_name’].”</option>”;
}
echo “</select>”;
}
else
{
$result = mysql_query(“select * from category”);

echo “<select name=”cat” class=”formtextbox” onChange=”javascript:document.cat_select.submit();”>”;
while ($row = mysql_fetch_array($result))
{
echo “<option value=”.$row[‘cat_id’];
if($cat == $row[‘cat_id’])
echo ” SELECTED”;
echo “>”.$row[‘cat_name’].”</option>”;
}

echo “</select>”;

if(!isSet($sub_cat))
{
echo “<br><br><span class = “maroontext”>Please select sub category </span>”;
$result1 = mysql_query(“select * from sub_category where cat_id=$cat”);
echo “<br><br><select name=”sub_cat” class=”formtextbox” onChange=”javascript:document.cat_select.submit();”>”;
echo ” <option selected>Select Category</option>”;
while ($row = mysql_fetch_array($result1))
{
echo “<option value=”.$row[‘subcat_id’];
echo “>”.$row[‘subcat_name’].”</option>”;
}
echo “</select>”;

}

else
{
$result1 = mysql_query(“select * from sub_category where cat_id=$cat”);
echo “<br><br><select name=”sub_cat” class=”formtextbox” onChange=”javascript:document.cat_select.submit();”>”;
while ($row = mysql_fetch_array($result1))
{
echo “<option value=”.$row[‘subcat_id’];
if($sub_cat == $row[‘subcat_id’])
echo ” SELECTED”;
echo “>”.$row[‘subcat_name’].”</option>”;
}

echo “</select>”;

print “<br><br><form> <input type=”button” value=”Close Window” onClick=”window.close()”> </form></p> “;
echo ‘<script language=”JavaScript”>’;
echo “window.opener.document.forms[1].cat.value = ‘$cat’;n”;
echo “window.opener.document.forms[1].sub_cat.value = ‘$sub_cat’;n”;
echo ‘</script>’;
}

}

?>
</form></td>

</tr>
</table>
<p align=”center”>&nbsp;</p>
</body>
</html>

THanks
Dill

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@JPnycJan 09.2005 — You can't call a function from another HTML doc. You need to use a linked external JS file.
Copy linkTweet thisAlerts:
@HamsterpantsauthorJan 09.2005 — well maybe I didnt explain it correctly, if you look at http://coleshillbiz.co.uk/add.php and then click on "click here to select category and sub category", you can see how I have it working at the moment, but what I would like to do is have that script part of the add.php page. I have tried this but when I select from the drop down the form submits the info to the page that I have set in the form value field. What I would like to happen is that the page only submits the info when you click on the preview button and not when you select from the drop down.

Thanks in advance

Dill
Copy linkTweet thisAlerts:
@JPnycJan 09.2005 — Remove this onChange="java script:document.cat_select.submit(); from your script, and put onsubmit="java script:document.cat_select.submit();" inside the form tag.
Copy linkTweet thisAlerts:
@HamsterpantsauthorJan 09.2005 — Hi There,

Thanks for your reply. Tried that, but now nothing happens. Also when I click on the preview button, the form doesnt submit - have a look at http://coleshillbiz.co.uk/test.php, code below:

<? require ("config.php"); ?>

<?

$pageid= add;

$connection = mysql_connect($dbhost, $dbusername, $dbpassword);

$db = mysql_select_db($dbname);

?>


<? include ("_header.php") ;?>

<div class="hmaroon"> Add To Directory</div><br><br>

<table width="65%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td><p>Fill in the form below with the relevant information required and your

FREE web page and directory listing will be added shortly.

</p></td>
</tr>

</table>

<br>

<form action="add_confirm.php" method="post" name="add_link" onsubmit="java script:document.add_link.submit();" change="<? echo $PHP_SELF; ?>">

<table width="70%" border="0" align="left" cellpadding="0" cellspacing="0">

<tr>

<td width="630">

<div class="margin">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="4" bgcolor="#DAE4DA">
<tr bgcolor="#DAE4DA">
<td width="100%" class="T01">Business Info (This info will be used
to create your free page and will be published on Solihullbiz.co.uk)
</td>
</tr>
<tr bgcolor="#DAE4DA">
<td height="30"><div align="left"><span class="important">Fields
Marked with <img title="required field" src="images/red_star_gb.gif" width="15" height="15"> are
required!!</span></div></td>
</tr>
<tr valign="top" bgcolor="#DAE4DA">
<td height="30">
<input name="image_name" type="hidden" value="<? echo $_POST['image_name']; ?>">
<a href="#" onclick="window.open('/fileupload/upload.php','popuppage','width=400,height=300,top=20,left=100');"><img src="images/upload_button.gif" border="0"></a>
( <strong>File may be no larger than 15 KB (15000 bytes).)</strong></td>
</tr>
<tr>
<td><strong>Select the Category and Sub-Category you
would like your listing to appear: <span class="important"><img src="images/red_star_gb.gif" width="15" height="15"></span></strong></td>
</tr>
<tr>
<td>

<input name="cat" type="text" value="<? echo $_POST['cat']; ?>">
<input name="sub_cat" type="text" value="<? echo $_POST['sub_cat']; ?>">
<a href="#" onclick="window.open('cat_subcat_ddm.php','popuppage','width=400,height=300,top=20,left=100');">click here to select category and sub category</a>
<br>
<?

//db connections

$cat = $_POST['cat'];

$sub_cat = $_
POST['sub_cat'];

if(!isSet($cat))
{
$result = mysql_query("select * from category");
echo "<select name="cat" class="formtextbox">";
echo " <option selected>Select Category</option>";

while ($row = mysql_fetch_array($result))
{
echo "<option value=".$row['cat_id'];
echo ">".$row['cat_name']."</option>";
}
echo "</select>";
}
else
{
$result = mysql_query("select * from category");

echo "<select name="cat" class="formtextbox">";
while ($row = mysql_fetch_array($result))
{
echo "<option value=".$row['cat_id'];
if($cat == $row['cat_id'])
echo " SELECTED";
echo ">".$row['cat_name']."</option>";
}

echo "</select>";

if(!isSet($sub_cat))
{
echo "<br><br><span class = "maroontext">Please select sub category </span>";
$result1 = mysql_query("select * from sub_category where cat_id=$cat");
echo "<br><br><select name="sub_cat" class="formtextbox">";
echo " <option selected>Select Category</option>";
while ($row = mysql_fetch_array($result1))
{
echo "<option value=".$row['subcat_id'];
echo ">".$row['subcat_name']."</option>";
}
echo "</select>";

}

else
{
$result1 = mysql_query("select * from sub_category where cat_id=$cat");
echo "<br><br><select name="sub_cat" class="formtextbox">";
while ($row = mysql_fetch_array($result1))
{
echo "<option value=".$row['subcat_id'];
if($sub_cat == $row['subcat_id'])
echo " SELECTED";
echo ">".$row['subcat_name']."</option>";
}

echo "</select>";




print "<br><br><form> <input type="button" value="Close Window" onClick="window.close()"> </form></p> ";
echo '<script language="JavaScript">';
echo "window.opener.document.forms[1].cat.value = '$cat';n";
echo "window.opener.document.forms[1].sub_cat.value = '$sub_cat';n";
echo '</script>';
}

}

?>

<? echo $_POST['cat']; ?> <? echo $_POST['sub_cat']; ?>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="center">
<input name="page" type="hidden" value="add_confirm">
<input name="SUBMIT" type="SUBMIT" value="Preview">
</div></td>
</tr>
</table>
<p>&nbsp;</p>
</div>


</td>


</tr>

</table>

</form>

</body>

</html>


</body>

</html>


Thanks

Dill
Copy linkTweet thisAlerts:
@JPnycJan 09.2005 — I assume that the space between java and script isn't present in your actual code. This board adds that space when you post the word.
Copy linkTweet thisAlerts:
@HamsterpantsauthorJan 09.2005 — no spave, just double checked.

Dill
Copy linkTweet thisAlerts:
@JPnycJan 09.2005 — what's the name of the function you want to call? It should be onsubmit="return functionName()"
Copy linkTweet thisAlerts:
@JPnycJan 09.2005 — You could also put the original call onclick of the submit button.
Copy linkTweet thisAlerts:
@HamsterpantsauthorJan 10.2005 — Hi JPnyc,

Thanks for all your help, finally sorted with some clues from you.

Regards

Dill
Copy linkTweet thisAlerts:
@JPnycJan 10.2005 — Splendid! Cheers!
×

Success!

Help @Hamsterpants spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...