Welcome to WebmasterWorld Guest from 54.145.144.101

Forum Moderators: open

Message Too Old, No Replies

changing action attribute of form

problems in IE

   
12:56 pm on Jan 24, 2008 (gmt 0)

5+ Year Member



Hello,

I have a form and i need to change the action attribute of the form, the problem is that i have an input element named action also - this is throwing it out in IE. here is simplified version.

<form name="form" method="post" action="">
<input type="hidden" name="action" value="1">
<input type="submit" name="sub" value="submit">
</form>

now i cannot go like this
document.form.action = "newpage.html";
or any sort of getElementById method as this action attribute exists inside the form.
I cant even do it with setAttribute()

Is there anysort of method for getting specifically the action attribute of the form? something like setFormActionAttribute() ;)

This is specifically an IE problem, works fine in FF.

Thanks for any help.
Ally

5:45 pm on Jan 24, 2008 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



<form name="form" id="my_form" method="post" action="">
<input type="hidden" name="action" value="1">
<input type="submit" name="sub" value="submit">
</form>

document.getElementById('my_form').action = "newpage.html";

Although I would find another way at all costs - if JS is disabled, the form will submit to "itself" which is equivalent to refreshing the page.

10:02 am on Jan 25, 2008 (gmt 0)

5+ Year Member



Thanks rocknbill.
unfortunately i am working on someone elses system and the way they have built iT (PHP to write XML and XLST to template) means that the same form tag is used through out and it already contains an ID tag

<form name="form" method="post" action="" id="form">

this means that the ID tag cannot be changed to a different one.

even though
document.getElementByID("form").action = "test.html";
doesnt work as it is looking for the element form.action and not the attribute action. strange - only in IE.

I have no idea why this would be - it is not critical to my project and have used a completely different method to get round this but am still just curious as to why this wouldnt work.

Thanks
Ally

8:04 pm on Jan 25, 2008 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



All right then.

Can you determine which form it is by index? If it's the only or first form on the page (via order in the source code), this will be 0 (zero.) If it's got two forms on the page and it's the second one, the index is 1, and so forth.

document.forms[0].action='mypage.html";

5:42 pm on Jan 29, 2008 (gmt 0)

5+ Year Member



Hi rocknbill.
sorry i took so long to reply.

There is only 1 form per page and it is always the same format. No matter what i tried i couldnt target the action attribute of the form. I even tried copying the action element, renaming it, destroying the old element, targeting the action attribute and then copying back the element - but that didnt work either.

I gave up after that and found a different way to achieve what i needed.

After thinking for a bit the only possible way that might work would be to clone the element and then rename it and then do a DOM refresh in order to get IE to not recognise this element... Dunno, its all startin to get a bit heavy at that point in order to do something simple.

Thanks for your help anyway.

Ally

 

Featured Threads

Hot Threads This Week

Hot Threads This Month