/    Sign up×
Community /Pin to ProfileBookmark

Changing form action in IE

I’ve got a form with two submit buttons and if one of them is clicked it should change the action of the form. For some stupid reason the code below isn’t working.

<input type=”submit” name=”send” value=”send”
onClick=”javascript: document.forms[0].action=’sender.php'”>

IE complains that there is no such property or method called action for the form object. If i put “forms[0].ACTION=….” it dowsn’t give an error but doesn’t change the action at all. I’ve read that IE didn’t support the changing of action in IE v3 put i’m using v6. Please help!!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@JonaFeb 27.2003 — Try using two forms
Copy linkTweet thisAlerts:
@bedeauthorFeb 27.2003 — I'd rather not. I'm posting the same elemetns to both scripts so its definately the easiest thing to do. I don't want a work around, there should be a simple explanation for it.
Copy linkTweet thisAlerts:
@JonaFeb 27.2003 — DO'H! I was thinking something else... Yeah, hehe, I getcha. Sorry, I don't really know.
Copy linkTweet thisAlerts:
@bedeauthorFeb 27.2003 — no luck. Still "object does not support this property or method". I've checked my code many times over and everything seems to be fine. It doesn't complain when I change the method, enctype or any other property. And why doesn't it complain when I put a property name in uppercase? I can even put "this.form.HJKHKJ='blah'" and it doesn't give me an error. Did I mention I hate Javascript & DOM?
Copy linkTweet thisAlerts:
@NedalsFeb 27.2003 — <input type="submit" name="send" value="send"

onClick="java script: document.forms[0].action='sender.php'">[/quote]

If this is a direct paste of your code, the problem is simply that 'javascript' in one word although you don't need it at all.

<input type="submit" name="send" value="send"

onClick="document.forms[0].action='sender.php'">

should work.
Copy linkTweet thisAlerts:
@bedeauthorFeb 27.2003 — OK, I'm an idiot. I had a hidden field called "action" which it was obviously getting confused with. I just thought it would have only assumed I was referencing the hidden field if I'd tried to access one of its properties.

(eg document.forms[0].action.value='blah')
×

Success!

Help @bede spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...