pass two javascript form funtions - help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: pass two javascript form funtions - help

  1. #1
    Join Date
    May 2006
    Posts
    1

    Cool pass two javascript form funtions - help

    I have two JS functions on a form. First function is "function checkData", to validate the form info, Second is "function setAction(frm)" to determin what action to take based on a radio button selection. I can't seem to get the form to run through the validation first, then run the action function based on a radio button selection.

    Code Function One:
    Code:
    <script><!--
    function checkData() {
            var text = "Enrollment Error:"   
            var correct = true 
                    if (document.Rebate.code.value != '800') {correct = false; text += "\nThe application code you entered is incorrect"}
                    if (document.Rebate.name.value == "") {correct = false; text += "\nPlease enter your name"}
                    if (document.Rebate.address.value == "") {correct = false; text += "\nPlease enter your address"}
                    if (document.Rebate.city.value == "") {correct = false; text += "\nPlease enter your city"}
                    if (document.Rebate.state.value == "") {correct = false; text += "\nPlease enter your statecode"}
                    if (document.Rebate.zip.value == "") {correct = false; text += "\nPlease enter your zip code"}
    				if (document.Rebate.area.value == "") {correct = false; text += "\nPlease enter your area code"}
                    if (document.Rebate.phone.value == "") {correct = false; text += "\nPlease enter your phone number"}
    				 if (document.Rebate.interest.value == "") {correct = false; text += "\nPlease enter your location of interest"}
                else if (correct == setAction(frm))
            else {alert(text)}
    }
    
    //-->
    </script>
    Code Function Two:
    Code:
    <script type="text/javascript">
    function setAction(frm){
    act = '';
    	for(x=0;x<frm.interest.length;x++){
    		if(frm.interest[x].checked){
    			act = frm.interest[x].value;
    		}
    	}
    	
    	if(act == 'flagler'){
    		frm.action = 'rebate_enrollment_action_flagler.asp';
    	}
    	else if(act == 'nbrevard'){
    		frm.action = 'rebate_enrollment_action_nbrevard.asp';
    	}
    	else if(act == 'cbrevard'){
    		frm.action = 'rebate_enrollment_action_cbrevard.asp';
    	}
    	else if(act == 'sbrevard'){
    		frm.action = 'rebate_enrollment_action_sbrevard.asp';
    	}
    	else if(act == 'indianriver'){
    		frm.action = 'rebate_enrollment_action_indianriver.asp';
    	}
    	else{
    		alert('Please choose an option');
    		return false;
    	}
    }
    </script>
    Code:
    <form name="form1" method="post" action="" onSubmit="return checkData()">

  2. #2
    Join Date
    Jan 2005
    Posts
    413
    You should combine the 2, and you need to return false to make the call you have correct. You only call with the keyword "return" if the function being called returns something. CheckData doesn't, at present.

    But I would make them one function, that'll solve all the problems.

  3. #3
    Join Date
    Jan 2005
    Posts
    413
    By the way, the script tag is missing the type attribute.

Similar Threads

  1. Replies: 3
    Last Post: 06-14-2002, 12:27 AM
  2. Replies: 2
    Last Post: 09-04-2001, 02:51 PM
  3. pass a form to a web user control (pagelet)
    By Annie Wang in forum ASP.NET
    Replies: 0
    Last Post: 05-24-2001, 04:07 PM
  4. pass value to javascript in xsl
    By shailesh in forum XML
    Replies: 0
    Last Post: 02-27-2001, 02:37 PM
  5. Sample Sites.
    By Murray Foxcroft in forum Web
    Replies: 5
    Last Post: 11-02-2000, 02:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center