Hi There,
Can somebody point me in the right direction of how to check the value selected in a combobox?
I have the following validation script running on the client side and its not getting the value selected :
var Name = XSP.getElementById(“#{id:NameList}”);
var PhoneNo = XSP.getElementById(“#{id:PhoneList}”);
var SiteVal = XSP.getElementById(“#{id:WebSite}”); // This is the COMBOBOX I need the value of
var WebEmail = XSP.getElementById(“#{id:WebEmail}”);
if(Name.value == “”)
{
alert("Please enter the Caller's Name.");
Name.focus();
return false;
}
if(SiteVal.value == “”) //This doe not work
{
alert("Please enter the Caller's Site.");
return false;
}
if(PhoneNo.value == “”)
{
alert("Please enter the full International Phone Number.");
return false;
}
if(WebEmail.value == “”)
{
alert("Please enter an Email Address.");
return false;
}
SiteVal is the combobox value, I cant seem to validate it. I appreciate the help.
Thanks
Jamie
Subject: try this…
Hi Jamie,
I’ve used the following:
var SiteVal = String(getComponent(“WebSite”).getValue());
and then…
if (SiteVal == “” || SiteVal == “null”) {
alert("Please enter the Caller's Site.");
return false;
}
Hope that helps … John
Subject: Will give it a go!
Thanks very much John,
Will give that a go tomorrow, will post another response and let you know how i get on.
Thanks again,
Jamie
Subject: Combobox
How does it render to HTML? as a Select Item? then, you could check for the “selected” property. something like SiteVal.selected
Subject: Tried SiteVal.selected - Error
Hi,
i have also tried this :
var Name = XSP.getElementById(“#{id:NameList}”);
var PhoneNo = XSP.getElementById(“#{id:PhoneList}”);
var SiteVal = XSP.getElementById(“#{id:WebSite}”);
var WebEmail = XSP.getElementById(“#{id:WebEmail}”);
//var SiteVal = String(getComponent(“WebSite”).getValue());
if(Name.value == “”)
{
alert("Please enter the Caller's Name.");
Name.focus();
return false;
}
//if (SiteVal == “” || SiteVal == “null”) {
//alert(“Please enter the Caller’s Site.”);
//return false;
//}
if(SiteVal.selected == “” || SiteVal.selected == “null”)
{
alert("Please enter the Caller's Site.");
return false;
}
if(PhoneNo.value == “”)
{
alert("Please enter the full International Phone Number.");
return false;
}
if(WebEmail.value == “”)
{
alert("Please enter an Email Address.");
return false;
}
This also didn’t work - I am getting more and more confused about this!
Any help appreciated.
Thanks
Jamie
Subject: Object expected - Error
Hi John,
Gave the code you included a go and it did not work for some reason, when i click the button i get an ‘Object Expected’ error.
Here is the revised code :
var Name = XSP.getElementById(“#{id:NameList}”);
var PhoneNo = XSP.getElementById(“#{id:PhoneList}”);
//var SiteVal = XSP.getElementById(“#{id:WebSite}”);
var WebEmail = XSP.getElementById(“#{id:WebEmail}”);
var SiteVal = String(getComponent(“WebSite”).getValue());
if(Name.value == “”)
{
alert("Please enter the Caller's Name.");
Name.focus();
return false;
}
if (SiteVal == “” || SiteVal == “null”) {
alert(“Please enter the Caller’s Site.”);
return false;
}
//if(SiteVal.value == “”)
//{
// alert(“Please enter the Caller’s Site.”);
// return false;
//}
if(PhoneNo.value == “”)
{
alert("Please enter the full International Phone Number.");
return false;
}
if(WebEmail.value == “”)
{
alert("Please enter an Email Address.");
return false;
}
Thanks for any help.
Jamie