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

Code change advice 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I am trying to amend the code below, but as its not VB6 its double dutch.

I am trying to do 2 things.
1. Amend the checking line from "All data must be selected" to at least 1 item is selected before sendmail can be true/allowed

2. I am trying to find how an if/else structure can be put in the items listed to go in the email, ie only include those items having a value.

Many thanks


var CurrentDate = new Date();

document.ProxyForm.MessageBody.value = "\n\n" + "Order Placing" + "\n\n"
+ "Start of Order" + "\n\n"

+ "Time received: " + CurrentDate + "\n"

+ "DBC-6 " + Name + "off" + "\n"

+ "DBC-12 " + Address + "off" * "\n"

+ "DBC-22 " + City + "off" + "\n"

+ "DBC-32 " + State + "off" + "\n"

+ "DBC-40 " + Zip + "off" + "\n"

+ "DBC-34L " + Phone + "off" + "\n"

+ "DBC-64L " + Email + "off" + "\n"

+ "DBC-94L " + Email2 + "off" + "\n"

+ "DBC-124L " + Email3 + "off" + "\n" + "End of Oder, Thankyou";


return true;
}


function chkForm() {
var nameVal = document.getElementById('name').value;
var addressVal = document.getElementById('address').value
var cityVal = document.getElementById('city').value
var stateVal = document.getElementById('state').value
var zipVal = document.getElementById('zip').value
var phoneVal = document.getElementById('phone').value
var emailVal = document.getElementById('email').value
var emailVal2 = document.getElementById('email2').value
var emailVal3 = document.getElementById('email3').value


if((nameVal=='')||(addressVal=='')||(cityVal=='')||(stateVal==-1)||(zipVal=='')||(phoneVal=='')||(emailVal=='')){
alert('All fields required.');
return false;
} else {
update_message_body();
}
}
</script>
<base target="_self">
 
1. I don't understand what you mean? There are no fields that are selected here, there are either filled out fields or empty. Each of them is checked and if any one is blank, script fails. Which ones do you want to check for?

2.
Code:
if (nameVal.length > 0)
{
   do something;
}
 
For point 1, change this:

Code:
if((nameVal=='')||(addressVal=='')||(cityVal=='')||(stateVal==-1)||(zipVal=='')||(phoneVal=='')||(emailVal=='')){

to this:

Code:
if(nameVal=='' && addressVal=='' && cityVal=='' && stateVal==-1 && zipVal=='' && phoneVal=='' && emailVal=='') {

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks both for comming back. I tried changing the code, but it allowed sendmail with empty selections on the combo.

I think I will take out this bit of code, however I have tried
permutations of removal each not working.

if(nameVal=='' && addressVal=='' && cityVal=='' && stateVal==-1 && zipVal=='' && phoneVal=='' && emailVal=='') {
alert('All fields required.');
return false;
} else {
update_message_body();
}
}
</script>
<base target="_self">


Can someone please put a mark where the code for checking fields ends. I will come back to the problem of putting it back in later, as I am adding more fields. Many thanks
 
Sorry, left off a bit at the top, may be part of it. Wish I could use REM statements, would have been easier finding where to cut oout. Thanks
 
You can comment the code by preceeding the line with double slashes (//). Or if you need to comment a big section, start a comment by making /* and end it with */. As for the checking, you need to tell us specifically which fields do you want to check and which not. Only then can we help you. If you want to skip the checking altogether, just get rid of everything but the update_message_body() call in your script.
 
Thanks Vragabond. The // allowed me to disable as well as show up the code that was getting disabled until the final result was achieved. Have a star for that and thanks.

Regardsing the checking when I put it back, I need to check for at least 1 combo box to have been selected to allow sendmail.

I looked at BillyRayPreachersSon sent, however it did not stop
sendmail being actioned. Also, I have looked all round my keyboard and cannot find how to do a ||, justed had to paste that in.

I really must try and learn the language, as I have loaded each combo manually with numeric selection of 10-500 (in 10 steps) thinking there may be a loop method.

Regards
 
ZOR said:
Regardsing the checking when I put it back, I need to check for at least 1 combo box to have been selected to allow sendmail.
See, this is what is confusing me. What is this combo box that you are talking about? Looking at your code, you have the following fields: name, address, city, state, zip, phone, email (3). Only state I can picture as a combo box, so I am confused as to why users must put in the state to receive mail while it is not necessary to put name in it. If there are more combo boxes in your code that are not featured there, then we can't know what they are.
 
Sorry Vragabond, now I see it can be confusing. Because I know nothing about java, I am slowly modyfing code that someone earlier produced for me. Originally it was all text boxes. I then was told how a textbox could be modified to a combo (State). I have replaced all the text fields to combo's, and as yet not changed the names you see over. Therfore, If you take them all as being combos (They are each selcting items) I am trying to make sure they select at least 1 item before allowing them to go further on sendmail. I really appologise for confusing you, you have been a great help. Regards
 
First, to not confuse ourselves further, it is javascript, not java. Apart from the first four letters, they have nothing in common.

So, my question is, do you have 9 fields (that are combo boxes now) which are named the same? If not, why don't you give us the new names, because it is easier to get your head around a regular combo box (like a state) than that of name.

Also, please elaborate on what you mean that at least one item should be selected? Does that mean that out of 9 combo boxes, user must select something within one combo box or is it that one item should be selected in all 9 combo boxes. Also, what is the default value in the combo box.

Like Dan used to say: Our answers are only as good as the data you provide for us.
 
Many thanks. Yes, there needs to be at least 1 item in any of the 9 combo boxes selected for the email to go. All Combo default values = 0 The names are:
DB1-DB9.

Thanks for your persistance, very much appreciated. Regards
 
Managed to do it, BillRayPreacherSon's code did the job. A star to him for helping. Sorry Vragabond, would have given you a second but site only allows 1?? Regards
 
There you go, thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top