Solved

setAttribute or writeAttribute in IE

Posted on 2010-09-14
13
908 Views
Last Modified: 2012-05-10
Greetings,

I have a form in which the user can either upload a file containing a list of widgets or manually enter the widgets into a text field. If the user manually enters the widgets into the text field, I use AJAX to serialize the form elements, send the data to the server, and process the response. If the user manually uploads a file I use an iframe to simulate a file upload with AJAX.

The issue is that the button to submit the form must only submit the form if the user is uploading a file of widgets. Therefore the input button must be of type "submit". The form must not be submitted if the user is manually entering the widgets in a text field. Therefore the input button must be of type "button" (to prevent the form from submitting) because the processing takes place on the page with theform.

The solution I came up with is depending on whether the user uploads the file or manually enters data, I use (or would like to use) Prototype JS's writeAttribute method to change the type attribute from "submit" (for the file upload) to "button" (for the manual entry) on the button to submit the request.

Of course IE has seizures with the writeAttribute and setAttribute methods.

Questions:

1. is there perhaps a better way to change the submission control of the form?
2. What method is cross-browser compatible to change the "type" attribute of an input tag and the "action" attribute of a form tag?

Cheers!
0
Comment
Question by:strimp101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
13 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33674103
1. I would think it was setAttribute and getAttribute
2. simply return false in the onSubmit:

<form action="someaction.php" onSubmit="ajax(this); return false">
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 33674403
<<is there perhaps a better way to change the submission control of the form?>>
You can submit the form like this

document.forms[0].action = ""; //mention the server side script name
document.forms[0].submit();

so the button can be of type 'button' only and still form can be submit through javascript
0
 

Author Comment

by:strimp101
ID: 33674598
I ended up keeping the input type as button and adding the action to the form. I used form.submit() to submit the form once we realized that it was supposed to be a form submission.
0
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

Author Closing Comment

by:strimp101
ID: 33674605
All I ended up needing was the submit() function.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33674616
why grade C?
0
 

Author Comment

by:strimp101
ID: 33677433
C is for an average answer. All gurvinder372 did was point out a method I temporarily overlooked. If you want "grade inflation" I'll change it to an A. Why offer A, B, C in the first place?
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33679133
Your question was <<is there perhaps a better way to change the submission control of the form?>>
what else did you expected me to tell you other than submit() function?
Let me know what else were you expecting. It will help me in helping you better in future
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33679450
I would still surmise that my suggestion may a better one depending on the script you use to send the data.
0
 

Author Comment

by:strimp101
ID: 33681606
Bottom line is that gurvinder aided me in solving my problem. I should have just provided an A in the first place. I'm a trial member and not sure the politics/benefit of As v. Bs, etc. Thanks for the help...
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33681808
Hi Strimp, Welcome to EE.

For some of us, a "B" is expected for a link to a working solution that helps you fix your issue and an "A" for actual code. The more code/Information YOU provide, the more complete solutions you will receive. For example I still do not know enough of your setup to judge my own suggestion.

That is why we expect you to provide more information when prompted and we can help you better.

Re-reading the question makes me think you want this:

<script type="text/javascript">
function validate(theForm) {
  if (theForm.widgetUploadField.value!="") {
    return true; // submit the form normally
  }
  iframeOrAjax(theForm); // instead use the iframe
  return false; // cancel the normal form submission
}
</script>
<form onSubmit="return validate(this)">
<input type="file" name="widgetUploadField" value="" />
.
.
<input type="submit" />
</form>
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33683328
<<I'm a trial member and not sure the politics/benefit of As v. Bs, etc. Thanks for the help...>>
No need to worry about politics of A's and B's. Believe me, there are plenty of experts in EE and experts like me are not irreplaceable.
I think the intention of Moderator is not to tell you that you need to give A's to get into good books of Experts, or be nicer to Experts (by giving them more points). But just to assert to you about how to give points (pardon my language if i am not articulate enough).
My intention was just to reason you about the grade and to know what was missing in my answer. Especially when you mentioned that <<All I ended up needing was the submit() function.>> #33674605
0
 

Author Comment

by:strimp101
ID: 33693775
mplungjan that is actually similar to what I did, thank you.

gurvinder372 thank you for the explanation.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question