Solved

setAttribute or writeAttribute in IE

Posted on 2010-09-14
13
890 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

778 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