Results 1 to 4 of 4

Thread: DIV Tag & Javascript Dilemma for Database

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation DIV Tag & Javascript Dilemma for Database

    I have a problem with the DIV tag (which I think is related with the Javascript). I need help because I cannot insert the form data into the database.

    I really need help!!!! Thank you in advance

    Code:
    <script type="text/javascript">
    var member_prices = new Array();
    member_prices["no"]=200.00;
    member_prices["discount"]=75.00;
    member_prices["yes"]=100.00;
    
    // getMemberPrice() finds the price based on the membership type
    // Here, we need to take user's the selection from radio button selection
    function getMemberPrice()
    {
        var MemberPrice=0;   
    	//Get a reference to the form id="signup" 
        var theForm = document.forms["signup"];
    	//Get a reference to the type the user Chooses name=member":
        var member = theForm.elements["member"];
        //Here since there are 3 radio buttons member.length = 3
        //We loop through each radio buttons
    	for(var i = 0; i < member.length; i++)
        {   
    	    //if the radio button is checked
            if(member[i].checked)
          {
                //we set MemberPrice to the value of the selected radio button
                //by using the member_prices array
                //We get the selected Items value
                //For example member_prices["no".value]"
                MemberPrice = member_prices[member[i].value];
                //If we get a match then we break out of this loop
                //No reason to continue if we get a match
                break;
            }
        }
        return MemberPrice;
    }
    
    
    
    
    var lunch_prices= new Array();
    lunch_prices["0"]=0;
    lunch_prices["yes"]=69.99;
    lunch_prices["no"]=0;
    
    //This function finds the Lunch prices based on the
    //drop down selection
    function getLunchPrice()
    {
        var LunchPrice=0;
        //Get a reference to the form id="signup"
        var theForm = document.forms["signup"];
        //Get a reference to the select id="lunch"
         var selectedLunch = theForm.elements["lunch"];
     
        //set Lunch Price equal to value user chose
        //For example lunch_prices[yes".value] would be equal to 69.99
        ConfdinnerPrice = lunch_prices[selectedLunch.value];
     
        //finally we return LunchPrice
        return LunchPrice;
    }
    
    
    
    
    
    
    
    function calculateTotal()
    {
        //Here we get the total price by calling our function
        //Each function returns a number so by calling them we add the values they return together
        var SignupPrice = getMemberPrice() + getLunchPrice ();
        
        //display the result
        var divobj = document.getElementById('total_payable');
        divobj.style.display='block';
    	divobj.innerHTML = "Total Signup Fee £" + SignupPrice;
    
    
    }
    
    function hideTotal()
    {
        var divobj = document.getElementById('total_payable');
        divobj.style.display='none';
    }</script>
    In the HTML part of my form, I have:
    Code:
    <style type="text/css">
    /*------------------Pay_total----------------*/
    #wrap div#pay_total
    {
        padding:10px;
    	font-size:14px;
        font-weight:bold;
    	color:#dde9f2;
        background-color:#3b7eb0;
    }
    
    </style>
    
    <form name="signup" id="signup" action="confirm.php" onsubmit="return validateForm(this);">
    Membership: <input type="radio" name="member" value="no" onclick="calculateTotal()" /> No <input type="radio" name="discount" value="discount" onclick="calculateTotal()" /> Student <input type="radio" name="member" value="yes" onclick="calculateTotal()" /> Yes
    <br /><br />
    
    <br /><br /><label><strong>Register for Lunch?</strong></label>
    <select id="lunch" name="lunch" onchange="calculateTotal()">
    <option value = "0" selected="selected">Please choose</option>
    <option value="yes">Yes</option>
    <option value="no">No</option>
    
    
    <p><div id="total_payable" name="total_payable"></div>

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    where is your validateForm() function?

    what makes you think this is a problem with the <div> tag (I'm not sure how it could be)?

    why can you not submit to the database? is your form submitting correctly? is your server-side script processing the submission correctly?

  3. #3
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Actually I figured its not the <div> problem... its not an actual input element thus thats why it wasnt inserting into the database. My validateForm function is toooo long to be posting it here so I didn't

    I also realised I had some errors when writing the PHP code for inserting into the Database.

    All has been resolved though

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •