Could you possibly just give your form an id attribute? Then onchange you
could just return $("#myformid").attr("action") and not have to mess with
any traversing.
-- Josh
----- Original Message -----
From: "briandichiara" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Thursday, May 08, 2008 1:58 PM
Subject: [jQuery] Re: Getting Parent Element using "this"
Ok, I tried this:
$(elm).parents().map(function () {
alert(this.tagName);
});
but the FORM never shows up. Reason is because the source looks like
this:
<table width="460" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" colspan="2">
<table border="0" cellspacing="1" cellpadding="3" width="100%">
<form Method="Post" Action="phoenix.zhtml?c=69181&p=OL-
home&t=SwitchQuote" >
<tr class="modBgQuoteShrtTicker">
<td colspan="4" nowrap="nowrap">
<span class="modQuoteShrtTicker">
<Select name="control_Symbol"
ONCHANGE="updateQuote(this);">
<option value="1" SELECTED="">opt 1</option>
<option value="2">opt 2</option>
</Select>
</span>
</td>
</tr>
</form>
I won't be able to alter the source, for it is nothing i have much
control over. So, how would i get the ACTION from the FORM above on
the SELECT menu's ONCHANGE event using jQuery?
On May 8, 2:30 pm, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:
jQuery is even easier than that. You can remove the need to put your
onchange inline like so:
var formAction = null;
$("select[name=some_name]").change(function() {
formAction = $(this).parent().attr("action");
});
This binds the anonymous function to set the variable formAction, to the
change event of the select.
-- Josh
----- Original Message -----
From: "briandichiara" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Thursday, May 08, 2008 12:18 PM
Subject: [jQuery] Getting Parent Element using "this"
> I have a page where I need to get a parent forms action after firing
> the onchange event on a select, like so:
> <form action="something">
> <select name="some_name" onchange="changeAction(this);">
> <!-- some options -->
> </select>
> </form>
> I can't figure out how to use "this" + a selector with jQuery,
> I've tried
> function changeAction(elm){
> var formAction = elm.$(":parent form").attr("action");
> }
> I really have no clue how to do effectively use "this" + a selector.