PDA

View Full Version : Can't get this to work right...


jaeman
12-23-2003, 07:43 AM
Hi there, i'm working on a form that either adds data to a file or goes back to the main menu.

The problem i'm having is that when the script checks the submit button it should do what i said above, Either confirm form fields are not empty & proccess the data or go back to the menu, The script is below & any help would be appreciated... jaeman

==

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>

<title>$title: ADD NEW ITEM</title>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

<script language="Javascript" type="text/javascript">
<!-- Confirm
function checkForm(addFORM) {


if(addFORM.action.value == "Finished") {
return true;
}
if(addFORM.action.value == "Add Item") {

if(addFORM.item.value == "") {
alert("You must enter an Item Name..!");
addFORM.item.focus();
return false;
}
if(addFORM.catagory.value == "Pick a Catagory") {
alert("You must choose a Catagory..!");
addFORM.catagory.focus();
return false;
}
if(addFORM.info.value == "") {
alert("You must enter some Item Info..!");
addFORM.info.focus();
return false;
}
if(addFORM.upfile.value == "") {
alert("You must enter a Photo File..!");
addFORM.upfile.focus();
return false;
}

}

return true;
}
// End Confirm -->
</script>

</head>

<body>
<form action="dataform.cgi?UPDATE" onsubmit="return checkForm(this)" method="post" enctype="multipart/form-data">
<H3>Goods Item DataBase Update</H3>
<table style="$table1">
<tr>
<td>Enter item name<br><input type="text" name="item" size="30"><br></td>
</tr>

<tr>
<td>
Enter item catagory
<br>

<select name="catagory" size="1">
<option value="Pick a Catagory">Pick a Catagory</option>
<option value="Clothing">Clothing</option>
<option value="Electrical">Electrical</option>
<option value="Furniture">Furniture</option>
<option value="Kitchen ware">Kitchen Ware</option>
<option value="Misc">Misc</option>
<option value="Sports Equipment">Sports Equipment</option>
<option value="Toys">Toys</option>
</select>

<br>
</td>
</tr>

<tr>
<td>Enter Item Info<br><textarea name="info" cols="40" rows="5"></textarea><br></td>
</tr>

<tr>
<td>Enter Item Photo<br><input type="file" name="upfile"><br></td>
</tr>

<tr>
<td>
<div align="center">
<br><br>
<input type="submit" name="action" value="Add Item">
&nbsp;&nbsp;
<input type="reset" value="Reset">
&nbsp;&nbsp;
<input type="submit" name="action" value="Finished">
</div>
</td>
</tr>
</table>
</form>
</body>

</html>

==

EOF

Willy Duitt
12-23-2003, 12:42 PM
Originally posted by jaeman
Hi there, i'm working on a form that either adds data to a file or goes back to the main menu.

The problem i'm having is that when the script checks the submit button it should do what i said above, Either confirm form fields are not empty & proccess the data or go back to the menu, The script is below & any help would be appreciated... jaeman



Which Submit button?

<input type="submit" name="action" value="Add Item">

<input type="submit" name="action" value="Finished">

If you want to confirm if the user wants to add another item
or is finished add a confirm to your Add Item function.

.....Willy

jaeman
12-23-2003, 08:54 PM
Hey there, The problem i'm having is that when the script checks the "add item" submit button it should check to see if the form fields are empty or not then proccess the form or focus on the empty field, The "finished" submit button should bypass the empty field checks & go back to the main menu WHICH it is not doing..! jaeman

Willy Duitt
12-24-2003, 12:00 AM
Originally posted by jaeman
The "finished" submit button should bypass the empty field checks & go back to the main menu WHICH it is not doing..! jaeman

Shoulda, coulda, woulda.... :rofl: :rofl: :rofl:

Okey Dokey,
Happy Holidays;

.....Willy

jaeman
12-24-2003, 12:44 AM
What was the use of that monkeyman..?

Willy Duitt
12-24-2003, 12:50 AM
Take a hint monkeyboy

If you want to confirm if the user wants to add another item
or is finished add a confirm to your Add Item function.


.....Willy

jaeman
12-24-2003, 01:02 AM
Take a hint monkeyboy

If you want to confirm if the user wants to add another item
or is finished add a confirm to your Add Item function.


But i don't want another confirm, that is not the problem, It's a good idea but not untill the first problem is fixed, There is a problem with the submit verifiying, Read the 2nd post again... jaeman

Willy Duitt
12-24-2003, 01:16 AM
You can not have two submit buttons with one doing this and another doing that.
You can not have two elements with the same name.
An <input type="submit"> does not have a value other than a label for the button.

Take the hint and make one submit with a confirm to continue or not.

And: I do not/did not appreciate your sarcasm

....Willy

Dr. Web
12-24-2003, 01:26 AM
easy, eeeeeeeeeeasy there.


Why don't you use two BUTTONS...
<input type=button value="Submit1" onClick="doThis()">
<input type=button value="Submit2" onClick="doThat()">

Or at least change the second submit, that doesn't need to do validations to a input type=button with an onclick to go back to the main menu (I assume you actually want to store something...)

jaeman
12-24-2003, 01:28 AM
Well thanks for a real answer there mate, I posted the question so i could be sure to make the right choice & i didn't post my question to be laughed at, So i think we gave & recieved...

And i was only reffering to your avatar... jaeman

jaeman
12-24-2003, 01:35 AM
Thanks Doc, Thats a better solution to the problem, That way i can use 2 functions, 1 for each submit[1,2], Should do nicely... jaeman

Willy Duitt
12-24-2003, 01:46 AM
Originally posted by jaeman
Well thanks for a real answer there mate, I posted the question so i could be sure to make the right choice & i didn't post my question to be laughed at, So i think we gave & recieved...

And i was only reffering to your avatar... jaeman

It's all good! :D

With your experience, I took it for granted that you would
understand what I was implying. If you was a noobie, I
woulda wrote the code for you.... ;)

Happy Holidays;
....Willy

jaeman
12-24-2003, 08:11 AM
It's all good!

With your experience, I took it for granted that you would
understand what I was implying. If you was a noobie, I
woulda wrote the code for you....


No problems, Still haven't mastered js yet so you could say i'm still a noobie:rolleyes:.

Knowing one way to do things is good but theres always another way & it's good to see other forumoids ways of doing things, Makes you a better coder in the long run.

Always the begineer, never the master.

I liked your suggestion to & the Doc pretty much assisted me with what i was looking for.

I wasn't having a go b4, I thought you would have clicked being the monkey as your avatar but in no way meant to insult you, Thanks... jaeman

jaeman
12-25-2003, 09:38 PM
Well i got around it & decided to use 1 submit button which was the field checker & the finish button as a std button that goes straight to the menu location...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>

<title>$title: ADD NEW ITEM</title>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

<script language="Javascript" type="text/javascript">
<!-- Begin Submit Check & Confirm
function addForm(addFORM) {
if(addFORM.item.value == "") {
alert("You must enter an Item Name..!");
addFORM.item.focus();
return false;
}
if(addFORM.catagory.value == "Pick a Catagory") {
alert("You must choose a Catagory..!");
addFORM.catagory.focus();
return false;
}
if(addFORM.info.value == "") {
alert("You must enter some Item Info..!");
addFORM.info.focus();
return false;
}
if(addFORM.upfile.value == "") {
alert("You must enter a Photo of the Item..!");
addFORM.upfile.focus();
return false;
}
return true;
}
// End Submit Check & Confirm -->
</script>

</head>

<body>
<form action="$fname?UPDATE" onSubmit="return addForm(this);" method="post" enctype="multipart/form-data">
<H3>$title: Update</H3>
<table style="$table1">
<tr>
<td>Enter item name<br><input type="text" name="item" size="30"><br></td>
</tr>

<tr>
<td>
Enter item catagory
<br>
SFORM

GetCATAGORY();

print <<FFORM;
<br>
</td>
</tr>

<tr>
<td>Enter Item Info<br><textarea name="info" cols="40" rows="5"></textarea><br></td>
</tr>

<tr>
<td>Enter Item Photo<br><input type="file" name="upfile"><br></td>
</tr>

<tr>
<td>
<div align="center">
<br><br>
<input type="submit" name="action" value="Add Item">
&nbsp;&nbsp;
<input type="reset" value="Reset">
&nbsp;&nbsp;
<input type="button" name="action" value="Finished" onClick="javascript:location.href='dataform.cgi';">
</div>
</td>
</tr>
</table>
</form>
</body>

</html>


EOF