Validate Required fields on submit

Posted on 07/09/2011. Filed under: JQuery |

function validate(){

//1-get all input with attr (isReq=true)

//2-check if the input contain data.

//-2a-if it contain data set req control to display ” else display *

var ctrlId = ;

$.each($(‘:input’), function(Index, ctrl) {

if (ctrl.isReq == ‘true’) {

//get the control id and see if it has any data

ctrlId = ctrl.id;

var x = ‘#lblmsg_’+ ctrlId

var value = $(‘#’+ ctrlId).val()

if(value.length > 0) {

$(‘#lblMsg_’+ ctrlId).attr({

value:

});

}

else

{

$(‘#lblMsg_’+ ctrlId).attr({

value:‘*’

});

}

}

});

}

//HTml ——————————————————————————————————–

<tr><tdcolspan=”2″><inputtype=button value=”validate” onclick=”javascript:validate();”/>

<inputtype=buttonvalue=”Submit” onclick=”javascript:SendForm();”/></td>

<tdclass=”style1″colspan=”2″><inputid=”txttest”name=”txttet”type=textisReq=”true”value=”"/>

<inputid=”lblMsg_txttest”name=”lblMsg_txttest”type=textvalue=”"/></td>

</tr>

//end Html——————————————————————————————————

Advertisement

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.