1,105,456 Community Members

problem in conditional oprator.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I am having the form

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="form.js"></script>
</head>
<?
mysql_connect('localhost','root','');
mysql_select_db('test'); 
$query="SELECT * FROM user";
$result=mysql_query($query);

?>
<div id="contact_form">
<form name="contact" action="">
<fieldset>
<label for="txn_unit" id="txn_unit">Txn Unit</label>
<SELECT name="name" id="name">
<OPTION value="">SELECT</OPTION>
<?
while($row=mysql_fetch_assoc($result))
{
?>
<OPTION value="<? echo $row['id']; ?>"><? echo $row['first_name']; ?></OPTION>
<?
}
?>
</SELECT>
<label class="error" for="name" id="name_error">Owner name field is required.</label>

<label for="description" id="desc_label">Description</label>
<input type="text" name="desc" id="desc" size="30" value="" class="text-input">
<label class="error" for="desc" id="desc_error">Description is required.</label>

<label for="income" id="income">Income</label>
<input type="text" name="income" id="income" size="30" value="" class="text-input">
<label class="error" for="income" id="income_error">Income field is required.</label>

<label for="expend" id="expend_label">Expend</label>
<input type="text" name="expend" id="expend" size="30" value="" class="text-input">
<label class="error" for="expend" id="expend_error">Expend field is required.</label>
<label class="error" for="expend" id="combine_error1">In Income and Expend field, one field is required.</label>
<label class="error" for="expend" id="combine_error2">In Income and Expend field, only one field is required.</label>


    <br />  
    <input type="submit" name="submit" class="button" id="submit_btn" value="ok" />
</fieldset>
</form>

and
the jquery file form.js-

$(function() {
  $('.error').hide();
  $(".button").click(function(){
     //validate and process from here
      $('.error').hide();

        var name=$("input#namee").val();
         if(namee=""){
         $("label#name_error").show();
         $("input#name").focus();
          return false;
          }

         var description=$("input#desc").val();
         if(description=="")
           {
              $("label#desc_error").show();
              $("input#desc").focus();
              return false;
           }

          var income=$("input#income").val();
          var expend=$("input#expend").val();
          if(income=="" && expend=="")
            {
              $("label#combine_error1").show();
              $("input#income").focus();
              $("input#expend").focus();
            }
           if(income!="" && expend!="")
            {
              $("label#combine_error2").show();
              $("input#income").focus();
              $("input#expend").focus();
            }

      var dataString='name='+namee+'&description='+description+'&income='+income+'&expend';
      $.ajax({
        type: "POST",
        url: "process.php",
        data: dataString,
        success: function() {
          $('#contact_form').html("<div id='message'></div>");
          $('#message').html("<h2>Transaction Saved</h2>")
          .hide()
          .fadeIn(1500,function(){
           $('#message').append("<img id='checkmark' src='images/check.png'/>");
            });
           }
        });
       return false;
    });
});

In this form if i submit form with blank fields then only description field error is showing.I need if a person submit the form with both income and expend field or leave both blank then it should show errors(combine_error1 or combine_error2).but it is not working.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

and it is also not posting value of input field 'name'.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

i have changed name with namee in our current code as not in the post.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I have corrected my code.only values from dropdown is not going to process.php file.

Question Self-Answered as of 1 Year Ago
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: