Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

setAttribute or writeAttribute in IE

Posted on 2010-09-14
13
Medium Priority
?
920 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:
Gurvinder Pal Singh earned 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

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

Expert Comment

by:Gurvinder Pal Singh
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:Gurvinder Pal Singh
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:Gurvinder Pal Singh
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
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 the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

636 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