dcsimg
Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 38

Thread: JavaScript Help

  1. #21
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    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.

  2. #22
    Senior Member
    Join Date
    Jan 2003
    Posts
    3,914
    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
    IT Blog: .:Computer Defense:.
    PnCHd (Pronounced Pinched): Acronym - Point 'n Click Hacked. As in: "That website was pinched" or "The skiddie pinched my computer because I forgot to patch".

  3. #23
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    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.

  4. #24
    Senior Member
    Join Date
    Jan 2003
    Posts
    3,914
    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
    IT Blog: .:Computer Defense:.
    PnCHd (Pronounced Pinched): Acronym - Point 'n Click Hacked. As in: "That website was pinched" or "The skiddie pinched my computer because I forgot to patch".

  5. #25
    Senior Member
    Join Date
    Jan 2003
    Posts
    3,914
    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

    Error: document.forms[0].elements[3].options has no properties
    Source File: http://www.XXX.ca/XXX/admin/addImages.php
    Line: 48
    Peace,
    HT
    IT Blog: .:Computer Defense:.
    PnCHd (Pronounced Pinched): Acronym - Point 'n Click Hacked. As in: "That website was pinched" or "The skiddie pinched my computer because I forgot to patch".

  6. #26
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    Ok, but we're getting closer! Lemme ruminate on it a bit. Also some work has floated my way that Ihave to deal with.

  7. #27
    Senior Member
    Join Date
    Jan 2003
    Posts
    3,914
    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
    IT Blog: .:Computer Defense:.
    PnCHd (Pronounced Pinched): Acronym - Point 'n Click Hacked. As in: "That website was pinched" or "The skiddie pinched my computer because I forgot to patch".

  8. #28
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    Should be in the form tag onsubmit='return validateProd();'

    Alsol you can't get the selectedIndex that way. Your 1st one was closer.

  9. #29
    Senior Member
    Join Date
    Jan 2003
    Posts
    3,914
    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
    IT Blog: .:Computer Defense:.
    PnCHd (Pronounced Pinched): Acronym - Point 'n Click Hacked. As in: "That website was pinched" or "The skiddie pinched my computer because I forgot to patch".

  10. #30
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    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
  •