DanDaBeginner Posted January 16, 2008 Share Posted January 16, 2008 . let me start by giving an example code: <script> var t = function() { var obj = document.getElementById("menu"); alert(obj.value); } </script> <form name="form1"> <select name="menu" id="menu" onchange="t(this);"> <option value="Pizza">Pizza</option> <option value="French Fries">French Fries</option> <option value="Ham Burger">Ham Burger</option> </select> </form> ok now my question is, the function accessed the select by its id, is there a way that i can get the form name (<form name="form1">) where this select came from? somethine like: <script> var t = function() { var obj = document.getElementById("menu"); var formName = getForm(obj); // and the value of the formName will be form1... } </script> thanks in advance, hope i explained it correctly.. Quote Link to comment Share on other sites More sharing options...
mainewoods Posted January 18, 2008 Share Posted January 18, 2008 http://www.w3schools.com/htmldom/prop_select_form.asp Quote Link to comment Share on other sites More sharing options...
priti Posted January 18, 2008 Share Posted January 18, 2008 Hi, One more way you can do is as follow : <script> var t = function(val,frm) { alert(frm.name) //It will display form name var obj = document.getElementById("menu"); alert(obj.value); } </script> <form name="form1"> <select name="menu" id="menu" onchange="t(this,this.form);"> <option value="Pizza">Pizza</option> <option value="French Fries">French Fries</option> <option value="Ham Burger">Ham Burger</option> </select> </form> Regards, Quote Link to comment Share on other sites More sharing options...
DanDaBeginner Posted January 18, 2008 Author Share Posted January 18, 2008 chee.. thanks.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.