Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need some help with ajax form submission

    I have been having some issues with a script, any help would be appreciated . For some reason data is not being posted through a simple ajax script I wrote a long time ago...it just up and stopped working with no errors.

    here is what i'm working with:

    script:

    Code:
    <script type="text/javascript" language="javascript">
    function SubmitForm() {
    var x=document.forms["incidentForm"]["priority"].value; 
    	var yy=document.forms["incidentForm"]["report"].value; 
    	var zz=document.forms["incidentForm"]["location"].value; 
    	if (x==null || x=="" || yy=="" || zz=="")
    	{
    		alert("You must select a priority and fill out the form completely!"); return false; 
    	} 
    		else 
    	{
    $.post('reports/saveLog.php', $("#incidentForm").serialize(), function(data) {
    					$('#incidentForm')[0].reset();
    					 
    				});
    
    }
    }
    </script>
    html:

    Code:
    <h3>Incident Log</h3>
      <form method="post" id="incidentForm" action="reports/saveLog.php">
        <input name="controlStation" type=hidden value="<? echo $user_call;?>">
        Priority:<BR>
        <select name="priority">
          <option value="">Select</option>
          <option value="Normal" style="background-color: Green;">Normal</option>
          <option value="Urgent" style="background-color: Yellow;">Urgent</option>
          <option value="Extreme" style="background-color: Red;">Extreme</option>
        </select>
        <BR>
        Call/Name: <BR>
        <input type="text" name="call" />
        <br />
        Location: <BR>
        <input type="text" name="location" />
        <br />
        Reported Time: <BR>
        <input type="repdate" name="repdate" id="date"/ size="16">
        <input type="button" value="<" onClick="show_current_date()" / class="button">
        <br />
        Comments/report: <BR>
        <textarea rows="5" cols="20" name="report" onFocus="this.value=''; this.onfocus=null;">Please enter a detailed description....
    	</textarea>
        <BR>
        <BR>
        <input type="button" onClick="SubmitForm();this.reset();" value="Add Report" class="button" />
        <BR>
        <BR>
    i'm sure i'm doing something wrong, I just cant spot it as I don't work with javascript that much. Any help/explanation would be greatly appreciated!

    csw

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,319
    Thanks
    23
    Thanked 614 Times in 613 Posts
    I don't think there is anything wrong with the above code. I think you do not have this file anymore. "reports/saveLog.php"

    When I made one the form does reset, before that nothing.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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