Showing both messages on when document is ready

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
CoolAsCarlito
Forum Contributor
Posts: 192
Joined: Sat May 31, 2008 3:27 pm
Contact:

Showing both messages on when document is ready

Post by CoolAsCarlito »

I apologize now for putting non php code inside of php tags but don't see where regular code can get bracketed. Anyway when I have this form loading its loading both messages when I told it to hide it and don't know why. Does anyone else? I looked inside the source code of the form and it's not saying the jquery function is involved.

Code: Select all

<script type="text/javascript">
    $(document).ready(function() {
    $('div.message message-error').hide();
    $('div.message message-success').hide();
    $("input.submit").click(function() {
        $('div.message message-error').hide();
        var divisionname = $("input#divisionname").val();
  		if (divisionname == "") {
        $("div.message message-error").show();
        $("input#name").focus();
        return false;
      } 
        var dataString = 'divisionname='+ divisioname;
        $.ajax({
        type: "POST",
        url: "bin/process.php",
        data: dataString,
        success: function() {
        $("div.message message-success").show();
        return true;
    }
  });
  return false;    
    });
  });
  
</script>
<!-- Form -->
				<form action="" name="divisionform">
					<fieldset>
						<legend>Add New Division</legend>

						<div class="field required">
							<label for="divisionname">Division Name</label>
							<input type="text" class="text" name="divisionname" id="divisionname" title="Division Name"/>
							<span class="required-icon tooltip" id="" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
						</div>
                        	<input type="submit" class="submit" name="submitdivision" id="submitdivision" title="Submit Division" value="Submit Division"/>
					</fieldset>
				</form>
                <div class="message message-error">
					<h6>Required field missing</h6>
					<p>Please fill in all required fields. </p>
				</div>
                <div class="message message-success">
					<h6>Operation succesful</h6>
					<p>Everything's going according to plan.</p>
				</div>
<!-- /Form -->
Last edited by pickle on Tue Nov 23, 2010 4:23 pm, edited 1 time in total.
Reason: Changed code highlighting
CoolAsCarlito
Forum Contributor
Posts: 192
Joined: Sat May 31, 2008 3:27 pm
Contact:

Re: Showing both messages on when document is ready

Post by CoolAsCarlito »

Issue has been fixed.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Showing both messages on when document is ready

Post by pickle »

FYI - the "PHP Code" button is just a shortcut to regular syntax highlighting.

You can post HTML code: [ syntax=html ][ /syntax ],
Javascript: [ syntax=javascript ][ /syntax ]
CSS: [ syntax=css ][ /syntax ]
(spaces added so the tags would show up)

And pretty much any other language you'll encounter when doing web development.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
CoolAsCarlito
Forum Contributor
Posts: 192
Joined: Sat May 31, 2008 3:27 pm
Contact:

Re: Showing both messages on when document is ready

Post by CoolAsCarlito »

Thank you for the added info.
Post Reply