PHP and javascript

Javascript coding ..

Moderators: macek, egami, gesf

anbarasuravi
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jun 09, 2010 2:29 am

PHP and javascript

Postby anbarasuravi » Wed Jun 09, 2010 2:32 am

Hi all,

I used a php for loop to create a block.the block has six fields.in javascript page i have to validate that block.(i.e) if any one field among six is empy
then it should show alert message.i have written conditions as follows

var from_month = $("select[id='from_month']").map(function(){return $(this).val();}).get();
var to_month = $("select[id='to_month']").map(function(){return $(this).val();}).get();
var from_year = $("input[id='from_year']").map(function(){return $(this).val();}).get();
var to_year = $("input[id='to_year']").map(function(){return $(this).val();}).get();
var designation = $("input[id='designation']").map(function(){return $(this).val();}).get();
var company = $("input[id='company']").map(function(){return $(this).val();}).get();

the above are the six fields which has multiple values (ie) array.

now i am writing condition as

for(var i=0;i<3;i++)
{
if(from_month[i] != 'Month' && to_month[i] == 'Month' && from_year[i] == 'Year' && to_year[i] == 'Year' && designation[i] == 'Designation' && company[i] == 'Company')
{ alert("Enter all details for Experience "+(i+1));
break;
}
else if(from_month[i] != 'Month' && to_month[i] != 'Month' && from_year[i] == 'Year' && to_year[i] == 'Year' && designation[i] == 'Designation' && company[i] == 'Company')
{ alert("Enter all details for Experience "+(i+1));
break;
}
else if(from_month[i] != 'Month' && to_month[i] != 'Month' && from_year[i] != 'Year' && to_year[i] == 'Year' && designation[i] == 'Designation' && company[i] == 'Company')
{
alert("Enter all details for Experience "+(i+1));
break;
}
etc
}


if i write conditions like this the number of lines of code is more.so any one have idea to make it simple using any loop..?

Suhoij
New php-forum User
New php-forum User
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov
Contact:

Re: PHP and javascript

Postby Suhoij » Tue Aug 17, 2010 3:39 am

How much blocks php generates or its only one block. If only one why Your code so difficult?


Return to “JavaScript”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest