Hey guys, Im using jquery dialog with the ajax post which suppose to send all the info of the dailog topost.php. but the create ad button which trigger the submit button does not work. i am not sure that im explain myslef really well but if you have look at my codes you might get some idea of what im trying to achieve.
$(function(){
var adtitle = $('.adname'),
price = $('.pprice'),
description= $('.des'),
Name = $('.Uname'),
allFields= $([]).add(adtitle).add(price).add(description).add(Name),
tips= $('p#validateTips');
function updateTips(t)
{
tips.text(t).effect('highlight',{},1500);
tips.text(t).css({"background-color":"yellow","font-size":"200%"});
}
// checking user input
function checkLength( UserInput, field,min,max)
{
if(UserInput.val().length > max || UserInput.val().length < min)
{
UserInput.addClass('ui-state-error');
tips.text('Length of '+ field + ' must be between ' + min+ ' and ' +max+'.' );
UserInput.focus();
return false;
}else{
return true;
}
}
$('#createAd').bind('.postAd',function(){
var bValid = true;
allFields.removeClass('ui-state-error');
bValids = bValid && checkLength(adtitle,'.adtitle', 5, 20);
bValids = bValids && checkLength(price,'.price',2,20);
bValids = bValids && checkLength(description,'.des',10,120);
bValids = bValids && checkLength(Name,'.Uname',5,25);
if (bValid){
var data = {
'adtitle' : $('.adttitle').val(),
'price' : $('.price').val(),
'des' : $('.des').val(),
'Uname' : $('.Uname').val()
};
$.post('post.php',data,function(){
});
}
});
$('#createAd').dialog({
bgiframe:true,
autoOpen:false,
height: 680,
maxHeight:700,
minHeight: 600,
width: 800,
maxWidth:1000,
minWidth:600,
//resizeable: false,
modal:true,
buttons: {
'Post an ad': function()
{
$(this).triggerHandler('.postAd');
},
Cancel: function(){
$(this).dialog('close');
}
},
close: function(){
allFields.val('').removeClass('ui-state-error');
}
});
$('li:eq(1)').click(function(){
$('#createAd').dialog('open');
});
});