Well if it has a variable number of elements, the 1st script I gave you is the one that you should try to get to work. That 1 will work for 1 element or 100 or any number in between.
Printable View
Well if it has a variable number of elements, the 1st script I gave you is the one that you should try to get to work. That 1 will work for 1 element or 100 or any number in between.
It would be perfect but unfortunately they don't want every field checked... There are 11 fields... This is repeated depending on how many files are uploadedQuote:
Originally posted here by JPNYC
Well if it has a variable number of elements, the 1st script I gave you is the one that you should try to get to work. That 1 will work for 1 element or 100 or any number in between.
1 File = 11 fields
2 Files = 22 Fields
3 Files = 33 Fields
and so on...
Out of every section they want fields 1, 2, 3, 4 and 9 to be required... I'm sure I can find a way to take your validation script and loop through it.. I think now it's just a matter of starting from scratch.... For me this is a learning experience... this is more javascript than I've ever looked at before...
Peace,
HT
Ok, then just check the fields like this
if (document.forms[0].elements[0].value=="") //this is for your 1st element
if (document.forms[0].elements[1].value=="") //this is for your 2nd element
if (document.forms[0].elements[2].value=="") //this is for your 3rd element
if (document.forms[0].elements[3].value=="") //this is for your 4th element
if (document.forms[0].elements[8].value=="") //this is for your 9th element
Now this way of referencing has to work. If it does not, then it's the inclusion of PHP elements in the JS code that is bollixing things up.
Hey Hey,
so i took that code, decided to leave out everything else (the looping to deal with multiple uploads, etc)
and doctored it to look like this
It works... however my 4th element... (Docket Number) is the only one I filled out and it's the only one it questions me about.... am I missing something?Code:<script type="text/javascript">
function validateProd() {
if (document.forms[0].elements[0].value=="") {//this is for your 1st element
alert('A Style Name is Required');
return false;
}
if (document.forms[0].elements[1].value=="") {//this is for your 2nd element
alert('A Style Code is Required');
return false;
}
if (document.forms[0].elements[2].value=="") {//this is for your 3rd element
alert('A Style Colour is Required');
return false;
}
if (document.forms[0].elements[3].value=="") {//this is for your 4th element
alert('A Docket Number is Required');
return false;
}
if (document.forms[0].elements[8].value=="") {//this is for your 9th element
alert('The Date Received is Required');
return false;
}
return true;
}
</script>
Peace,
HT
Hey Hey,
so I messed up that code a little more..
I changed the 4th element.... so that it would use the select box values... then I went on with the page... it submitted and went through... even though all 4 of the text boxes were wrong, only the docket number was correct..Code:<script type="text/javascript">
function validateProd() {
if (document.forms[0].elements[0].value=="") {//this is for your 1st element
alert('A Style Name is Required');
return false;
}
if (document.forms[0].elements[1].value=="") {//this is for your 2nd element
alert('A Style Code is Required');
return false;
}
if (document.forms[0].elements[2].value=="") {//this is for your 3rd element
alert('A Style Colour is Required');
return false;
}
if (document.forms[0].elements[3].options[document.forms[0].elements[3].selectedIndex].value=='0') {//this is for your 4th element
alert('A Docket Number is Required');
return false;
}
if (document.forms[0].elements[8].value=="") {//this is for your 9th element
alert('The Date Received is Required');
return false;
}
return true;
}
</script>
This warning came up
Peace,Quote:
Error: document.forms[0].elements[3].options has no properties
Source File: http://www.XXX.ca/XXX/admin/addImages.php
Line: 48
HT
Ok, but we're getting closer! Lemme ruminate on it a bit. Also some work has floated my way that Ihave to deal with.
Hey Hey,
Here's the final code
No errors are generated, however nothing happens either... I've tried it as both onClick and onSubmit... there is now no php being used in it... it's just JavaScript..Code:<script type="text/javascript">
function validateProd() {
if (document.forms[0].elements[0].value=="") {//this is for your 1st element
alert('A Style Name is Required');
return false;
}
if (document.forms[0].elements[1].value=="") {//this is for your 2nd element
alert('A Style Code is Required');
return false;
}
if (document.forms[0].elements[2].value=="") {//this is for your 3rd element
alert('A Style Colour is Required');
return false;
}
if (document.forms[0].elements[3].selectedIndex =='0') {//this is for your 4th element
alert('A Docket Number is Required');
return false;
}
if (document.forms[0].elements[8].value=="") {//this is for your 9th element
alert('The Date Received is Required');
return false;
}
return true;
}
</script>
Peace,
HT
Should be in the form tag onsubmit='return validateProd();'
Alsol you can't get the selectedIndex that way. Your 1st one was closer.
That's where it's been the entire time, but for fun I put it in the submit buttons onClick tag... still didn't workQuote:
Originally posted here by JPNYC
Should be in the form tag onsubmit='return validateProd();'
Alsol you can't get the selectedIndex that way. Your 1st one was closer.
As for selectedIndex are ya sure? The last one told me that there were no properties for that object... this one doesn't give any errors to me... I took it off a website.... I'll see if I can find the link.
Peace,
HT
Yeah, it should be what you had last time. Been a while since I validated a select dropdown, but I'm pretty sure that's the correct syntax.