PHP and javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anbarasu.ravi
Forum Newbie
Posts: 3
Joined: Wed Jun 09, 2010 5:02 am

PHP and javascript

Post by anbarasu.ravi »

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

Code: Select all

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

Code: Select all

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..?
Last edited by Benjamin on Wed Jun 09, 2010 6:16 am, edited 1 time in total.
Reason: Added [syntax=javascript] tags.
anbarasu.ravi
Forum Newbie
Posts: 3
Joined: Wed Jun 09, 2010 5:02 am

Re: PHP and javascript

Post by anbarasu.ravi »

I think this wil help u..

Code: Select all

<select title="State" name = "state" id = "state" class="mandatory_field">
			<option value="State">State</option>
			<?foreach($state as $var){?>
			<?if($var['state_name'] == $data['state']){?>
			<option value="<?=$var['state_name']?>"  selected="selected" ><?=$var['state_name']?></option>
			<?php }else{?>
			<option value="<?=$var['state_name']?>" ><?=$var['state_name']?></option>
			<?php }}?>
</select>
Last edited by Benjamin on Wed Jun 09, 2010 7:47 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
Post Reply