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-data>
else
<form action="xyz.asp">
End if
Webboy2008Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wdfdo1986Commented:
have a name to the form and then you can call the form from javascript. Then you can change action using some code like below

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";
        }
    }
RobOwner (Aidellio)Commented:
You can do that like this, see here http://jsfiddle.net/rjurd/Bqt9H/ 

javascript
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');
    }
    pf2.onclick = function() {
        myform.setAttribute('action','abc.asp');
    }
}

Open in new window


html

<form id='myform' enctype='multipart/form-data'>
    <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>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
COBOLdinosaurCommented:
change the form action to action="myscript(this)"

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();
}

Open in new window

 


Cd&
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Kiran SonawaneProject LeadCommented:
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>

Open in new window

Webboy2008Author Commented:
It is classic asp and javascript. No asp.net or jquery please.

thanks
RobOwner (Aidellio)Commented:
Please refer to my post above.  pure javascript no frameworks
Webboy2008Author Commented:
<form id='myform' enctype='multipart/form-data'> 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
RobOwner (Aidellio)Commented:
ok so the html goes back 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>

Open in new window


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');
    }
}

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.