พบกับบทความเกี่ยวกับคอมพิวเตอร์และ programming ได้ที่ http://articles.modoeye.com | บล็อกอาหาร
Javascript development / ถามเรื่อง radio button
kerori
kerori
Wed 13 Sep 2006 10:51:44

function radio_button_checker(){
var radio_choice = false;
for (counter = 0; counter < radioform.radiobutton.length; counter++)
{
if (radioform.radiobutton[counter].checked)
radio_choice = true;
}
if (!radio_choice)
{
alert ("กรุณาเลือก radio buttonก่อน!!! " )
return (false);

}

ถ้า radio มีเหลือ อันเดียว และคลิกเลือกแล้ว  แต่ก็ยัง alert(message); ทำยังไงดีค่ะ

เช็คดูจาก radioform.radiobutton.length ไม่ส่งค่า 1 มาจะส่ง undefined มา

 ถ้ามี radio หลายอัน ก้อเช็คได้ แต่ถ้ามีอันเดียว เช็คไม่ได้ จะแก้ยังไงดี

Administrator
Wed 13 Sep 2006 16:40:06
ลองทำการหาค่า radioform.radiobutton.length ว่าถ้ามี radio เพียงอีนเดียวมีค่าเท่าไหร่ครับ
น่าจะไม่เป็น Array ลองทำการตรวจสอบด้วย
if(radioform.radiobutton.length == "undefined")
//มี radio เพียงอันเดียว
else if(radioform.radiobutton.length > 0)
//มี radio หลายอัน
kerori
kerori
Thu 14 Sep 2006 10:53:32

ขอบคุณมากๆคะ

Reply
Name:
E-mail:
Home | Services | Forum | Classified | Directories | Support | Contact
ATOM feed RSS 0.9 feed RSS 1.0 feed RSS 2.0 feed
Copyright © 2005 - 2007 Modoeye.com, All Rights Reserved.
Disclaimer | Privacy policy | Term of Use | Term of Services
Valid XHTML Valid CSS! PHP: Hypertext Preprocessor MySQL database Apache Powered! FreeBSD Power to serve
Modoeye Sitemap Client login