Webboy2008
asked on
javascript upload object
<input checked type=""radio"" id=""PF"" name=""rdopaymenttype"" value=""4"">Nothing
<input checked type=""radio"" id=""PF"" name=""rdopaymenttype"" value=""5"">Upload
How can I do the following in javascript? Thanks
if the rdopaymenttype == 5 Then
<form action="abc.asp" enctype=multipart/form-dat
else
<form action="xyz.asp">
End if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
change the form action to action="myscript(this)"
then the function inthe js would be:
Cd&
then the function inthe js would be:
function myscript(x)
{
if (x.rdopaymenttype[0].checked)
{
x.action='abc.asp';
x.enctype='multipart/form-data';
{
else
{
x.action='xyz.asp';
x.enctype='text/plain';
}
x.submit();
}
Cd&
Here is the code to deal with this
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<script>
$(document).ready(function(){
update_form_attributes();
$("input[name=rdopaymenttype]").click(function(){
update_form_attributes();
});
});
function update_form_attributes()
{
if($("input[name=rdopaymenttype]:checked").val() == "5")
{
$("form").attr("action","abc.asp").attr("enctype","multipart/form-data");
}
else
{
$("form").attr("action","xyz.asp");
$("form").removeAttr("enctype");
}
}
</script>
<body>
<form>
<input type="radio" id="PF" name="rdopaymenttype" checked value="4">Nothing
<input type="radio" id="PF" name="rdopaymenttype" value="5">Upload
</form>
</body>
</html>
ASKER
It is classic asp and javascript. No asp.net or jquery please.
thanks
thanks
Please refer to my post above. pure javascript no frameworks
ASKER
<form id='myform' enctype='multipart/form-da ta'> is not supposed to be there as default.
because if first radio is selected, it will not be any upload there. remember, if it is 4, then
it acts normal like http post, when it is 5, it show browse button to allow upload.
Thanks
because if first radio is selected, it will not be any upload there. remember, if it is 4, then
it acts normal like http post, when it is 5, it show browse button to allow upload.
Thanks
ok so the html goes back to:
and the javascript is slightly changed to:
<form id='myform'>
<label for='PF1'>Nothing</label>
<input checked type="radio" id="PF1" name="rdopaymenttype" value="4" />
<label for='PF2'>Upload</label>
<input checked type="radio" id="PF2" name="rdopaymenttype" value="5" />
</form>
and the javascript is slightly changed to:
window.onload = function() {
var pf1 = document.getElementById('PF1');
var pf2 = document.getElementById('PF2');
var myform = document.getElementById('myform');
pf1.onclick = function() {
myform.setAttribute('action','xyz.asp');
myform.removeAttribute('enctype');
}
pf2.onclick = function() {
myform.setAttribute('action','abc.asp');
myform.setAttribute('enctype','multipart/form-data');
}
}
NOTE: This is just an example
function chgAction( action_name )
{
if( action_name=="aaa" ) {
document.forms[0].action = "/AAA";
}
else if( action_name=="bbb" ) {
document.forms[0].action = "/BBB";
}
else if( action_name=="ccc" ) {
document.forms[0].action = "/CCC";
}
}