-
February 3rd, 2006, 07:30 PM
#21
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.
-
February 3rd, 2006, 07:40 PM
#22
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.
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 uploaded
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
-
February 3rd, 2006, 07:46 PM
#23
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.
-
February 3rd, 2006, 07:58 PM
#24
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
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>
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?
Peace,
HT
-
February 3rd, 2006, 08:20 PM
#25
Hey Hey,
so I messed up that code a little more..
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>
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..
This warning came up
Peace,
HT
-
February 3rd, 2006, 08:49 PM
#26
Ok, but we're getting closer! Lemme ruminate on it a bit. Also some work has floated my way that Ihave to deal with.
-
February 3rd, 2006, 09:38 PM
#27
Hey Hey,
Here's the final code
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>
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..
Peace,
HT
-
February 3rd, 2006, 09:39 PM
#28
Should be in the form tag onsubmit='return validateProd();'
Alsol you can't get the selectedIndex that way. Your 1st one was closer.
-
February 3rd, 2006, 09:43 PM
#29
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.
That's where it's been the entire time, but for fun I put it in the submit buttons onClick tag... still didn't work
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
-
February 3rd, 2006, 09:57 PM
#30
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|