techzzz
asked on
Help With Forms
Hi...
Below is a script that I'm working on that submits several forms to a specified location with the click of only one submit button:
<head>
<script language=javascript>
<!--
function submitall()
{
document.form1.action = "http://www-form1-com"
document.form1.target = "iframe1";
document.form1.submit();
document.form2.action = "http://www-form2-com"
document.form2.target = "iframe2";
document.form2.submit();
document.thanks.location.h ref = "thanks.html";
return true;
}
-->
</script>
</head>
<body>
<iframe name="iframe1" width="1" height="1"></iframe>
<iframe name="iframe2" width="1" height="1"></iframe>
<iframe name="thanks" width="500" height="300"></iframe>
<FORM name="form1" method="post">
<INPUT type="text" name="name">
submit form 1?<input type="checkbox" name="operation" value="1">
</FORM>
<FORM name="form2" method="post">
<INPUT type="text" name="name">
submit form 2?<input type="checkbox" name="operation" value="2">
</FORM>
<input type="submit" value="Send" onclick="return submitall();">
</body>
As you can see - each form is submitted and then loaded into an invisible traget iframe (iframe1 and iframe2).
A thank you page is then loaded into a visible iframe named "thanks".
My question is this:
1- Is it possible to submit each form without the use of an invisible target iframe or window? Can javascript submit forms without actually opening the form action for each form?
2- Also, how can I allow my visitors to choose which forms the script submits to by using checkboxes? So if only the checkbox for form1 is checked, it only submits to:
document.form1.action = "http://www-form1-com"
All help is appreciated - thank you
Below is a script that I'm working on that submits several forms to a specified location with the click of only one submit button:
<head>
<script language=javascript>
<!--
function submitall()
{
document.form1.action = "http://www-form1-com"
document.form1.target = "iframe1";
document.form1.submit();
document.form2.action = "http://www-form2-com"
document.form2.target = "iframe2";
document.form2.submit();
document.thanks.location.h
return true;
}
-->
</script>
</head>
<body>
<iframe name="iframe1" width="1" height="1"></iframe>
<iframe name="iframe2" width="1" height="1"></iframe>
<iframe name="thanks" width="500" height="300"></iframe>
<FORM name="form1" method="post">
<INPUT type="text" name="name">
submit form 1?<input type="checkbox" name="operation" value="1">
</FORM>
<FORM name="form2" method="post">
<INPUT type="text" name="name">
submit form 2?<input type="checkbox" name="operation" value="2">
</FORM>
<input type="submit" value="Send" onclick="return submitall();">
</body>
As you can see - each form is submitted and then loaded into an invisible traget iframe (iframe1 and iframe2).
A thank you page is then loaded into a visible iframe named "thanks".
My question is this:
1- Is it possible to submit each form without the use of an invisible target iframe or window? Can javascript submit forms without actually opening the form action for each form?
2- Also, how can I allow my visitors to choose which forms the script submits to by using checkboxes? So if only the checkbox for form1 is checked, it only submits to:
document.form1.action = "http://www-form1-com"
All help is appreciated - thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I figured out what I was doing wrong. Please ignore my second question...
However, can you please show me how to use GET instead of POST and how to load an image to submit the forms?
Thanks
However, can you please show me how to use GET instead of POST and how to load an image to submit the forms?
Thanks
Do not have a fieldname called name
function submitall()
{
if (document.form1.operation. checked) {
url = 'http://www.form1.com/'+document.form1.action+'?'
url += 'firstname='+escape(docume nt.form1.f irstname.v alue)
window.frames["iframe1"].l ocation = url
}
if (document.form2.operation. checked) {
url = 'http://www.form2.com/'+document.form2.action+'?'
url += 'firstname='+escape(docume nt.form2.f irstname.v alue)
window.frames["iframe2"].l ocation = url
}
if (document.form1.operation. checked || document.form2.operation.c hecked) {
document.thanks.location.h ref = "thanks.html";
}
return false;
}
If you do not need to see the result and you can get the action to return an image, you can change
window.frames["iframe2"].l ocation = url
to
document.images["image1"]. src= url
and use
<img name="image1" src="dummy.gif">
instead of iframe
Michel
function submitall()
{
if (document.form1.operation.
url = 'http://www.form1.com/'+document.form1.action+'?'
url += 'firstname='+escape(docume
window.frames["iframe1"].l
}
if (document.form2.operation.
url = 'http://www.form2.com/'+document.form2.action+'?'
url += 'firstname='+escape(docume
window.frames["iframe2"].l
}
if (document.form1.operation.
document.thanks.location.h
}
return false;
}
If you do not need to see the result and you can get the action to return an image, you can change
window.frames["iframe2"].l
to
document.images["image1"].
and use
<img name="image1" src="dummy.gif">
instead of iframe
Michel
ASKER
Hi Michel,
Thank you. That works great.
One last question...
Can I hide the images using this?:
<span style="display: none;">
<img name="image1" src="dummy.gif">
</span>
or
<img name="image1" src="dummy.gif" width="1" height="1">
Thanks
Thank you. That works great.
One last question...
Can I hide the images using this?:
<span style="display: none;">
<img name="image1" src="dummy.gif">
</span>
or
<img name="image1" src="dummy.gif" width="1" height="1">
Thanks
Yes
ASKER
Thanks!
But, is it ok to use the same image for each form?
Like:
<img name="image1" src="dummy.gif">
<img name="image2" src="dummy.gif">
Thanks again
(I will increase the point value for this question). ;)
But, is it ok to use the same image for each form?
Like:
<img name="image1" src="dummy.gif">
<img name="image2" src="dummy.gif">
Thanks again
(I will increase the point value for this question). ;)
You of course need an image per form. If not, your submissions will cancel each other out
Just change your iframe1, iframe2 to image1, image2 (and the call to change the src instead of location too)
Just change your iframe1, iframe2 to image1, image2 (and the call to change the src instead of location too)
ASKER
Ok, I understand...
I guess what I was asking, was...
Can I use dummy.gif for each form?
Or do I need to create a different image for each form, like:
dummy1.gif
dummy2.gif
Thanks again
I guess what I was asking, was...
Can I use dummy.gif for each form?
Or do I need to create a different image for each form, like:
dummy1.gif
dummy2.gif
Thanks again
Ahh, sorry. You can use the same dummy.gif.
ASKER
Thank you very much for your help!
ASKER
Thanks, the checkbox function works great...
However, I'm confused.
1- How would I use GET and load an image to submit the forms? I did a search, but couldn't find anything...
2- Since I can't have the submit button outside of the form, how can I add multiple forms with different form names to one form?
Also, when I use onSubmit instead of onClick, it doesn't work.
Thanks again