Take the 2-minute tour ×

i have a contact form on http://daniloportal.com/NPC2/contact.html

Now this ajax script works very well, but i have other contact forms that i would like to use the same script for. so when i tried to create mulitple instances of the script, i noticed it stopped working because the ID name is not specifically ajax-contact-form. take a look at the code:

<form id="ajax-contact-form" action="">
  <input type="text" name="name" value="Name *" title="Name *" />
  <input type="text" name="email" value="Email " title="Email *" />
  <input type="text" name="email" value="Email *" title="Email *" />
  <textarea name="message" id="message" title="Message *">Message *</textarea>
    <div class="clear"></div>
  <input type="reset" class="btn btn_clear" value="Clear form" />
  <input type="submit" class="btn btn_blue btn_send" value="Send message!" />
<div class="clear"></div>

and heres the JS

$("#ajax-contact-form").submit(function() {
    var str = $(this).serialize();      
        type: "POST",
        url: "contact_form/contact_process.php",
        data: str,
        success: function(msg) {
            // Message Sent - Show the 'Thank You' message and hide the    form
            if(msg == 'OK') {
                result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
            } else {
                result = msg;
    return false;

Now if i were to switch that ID name on both and MATCH them, the script stops working- Theoretically it should work- not sure whats wrong with this.

as always any help is appreciated, thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

If you are trying to access two elements with the same id with jQuery - nothing gonna happen. Each element must have a unique identifier, otherwise you should use classes.

However, can you give us the markup of another form?

share|improve this answer
well the thing is Kristian i didnt have the same ID when i tried making two contact forms, i tried making separate ones. So for instance I would have one set of the code above with one ID and another set with another ID. The problem is though is that i cannot get this script to work with any other id name other than #ajax-contact-form, i cant understand why i cant change it –  Tetzuro Apr 19 '13 at 19:27
the real questions is why cant i switch the ID name from #ajax-contact-form to something esle –  Tetzuro Apr 19 '13 at 19:29
I think you should not have any problems with this, that's why I asekd you to post another form markup code to see if there's any problem. –  Kristian Vitozev Apr 19 '13 at 19:33
i know thats what im not getting, the other form of mark up code isint the issue. Its just the ID name- it strictly has to be #ajax-contact-form thats what i dont get –  Tetzuro Apr 19 '13 at 19:35
if i change it too #ajax-contact , it breaks :/ –  Tetzuro Apr 19 '13 at 19:37
show 1 more comment

Your Answer


