Jump to content

[SOLVED] accessing forms


DanDaBeginner

Recommended Posts

:). 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

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,

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.