homepage Welcome to WebmasterWorld Guest from 54.163.84.199
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
changing action attribute of form
problems in IE
Scally_Ally




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

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

 

rocknbil




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

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

Scally_Ally




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

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

rocknbil




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

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";

Scally_Ally




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved