Javascript novice

C

Craig G

i have the following little jscript function which i use to launch a modal
dialog

but what i want to do is check the values of txtAddress1 & txtAddress2 to
make sure they have values before lauching the dialog. but im not sure of
the syntax for it

function OpenPostCode2(idname, postBack)
{
var strReturn;

strReturn=window.showModalDialog('frmPostCode.aspx?Address1=' +
document.getElementById('txtAddress1').value + '&Address2=' +
document.getElementById('txtAddress2').value
,null,'status:no;dialogWidth:520px;dialogHeight:285px;dialogHide:true;help:n
o;scroll:no');

if (strReturn != null)
document.getElementById('txtPostcode').value=strReturn;
}


so i wanted to put something within it like

if (document.getElementById('txtAddress2').value=="") window.alert("Town
must be
populated") return;


but i dunno how!!!

any help would be greatly appreciated.

Cheers, and happy new year
Craig
 
G

Guest

Craig,

try this:

function OpenPostCode2(idname, postBack)
{

var strReturn;

if((document.getElementById('txtAddress1').value != "") &&
(document.getElementById('txtAddress2').value != "")){
//fields have been entered - proceed to modal window
strReturn=window.showModalDialog('frmPostCode.aspx?Address1=' +
document.getElementById('txtAddress1').value + '&Address2=' +
document.getElementById('txtAddress2').value

,null,'status:no;dialogWidth:520px;dialogHeight:285px;dialogHide:true;help:n
o;scroll:no');

if (strReturn != null)
document.getElementById('txtPostcode').value=strReturn;
}
else
{
//form is not complete - alert error to user
alert("You must complete all address fields");
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top