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.. Link to comment https://forums.phpfreaks.com/topic/86297-solved-accessing-forms/ 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 Link to comment https://forums.phpfreaks.com/topic/86297-solved-accessing-forms/#findComment-442459 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, Link to comment https://forums.phpfreaks.com/topic/86297-solved-accessing-forms/#findComment-442483 Share on other sites More sharing options...
DanDaBeginner Posted January 18, 2008 Author Share Posted January 18, 2008 chee.. thanks.. Link to comment https://forums.phpfreaks.com/topic/86297-solved-accessing-forms/#findComment-442581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.