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
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,

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.