-1

i want to create a form where user have two option for image upload , either they upload a image through a file upload option or they can input text URL of the image, the problem is that how can restrict a user to either of the one option, i though RADIO checked might help me but i didn't figure out how to use radio button to enable any of the one option, kindly help me in this, i am new in development and didn't have much knowledge of JavaScript as well.

<input name="file" type="radio" value="file" checked><input type="file" name="file">
<input name="file" type="radio" value="url" checked><input type="text" name="url" >
Dom
  • 38,906
  • 12
  • 52
  • 81
Syed
  • 25
  • 1
  • 7
  • Please post relevant javascript. Also look into this- http://stackoverflow.com/questions/5665915/how-to-check-a-radio-button-with-jquery – Dom Sep 15 '13 at 16:30
  • @ DOM , i didnt know about anything about javascript, kindly help me in this – Syed Sep 15 '13 at 16:32

1 Answers1

0

You can do this relatively easy. I added a class to your input that is going to show depending on the radio (I used type as the class), then with simple jQuery:

$("input:radio").change(function() {
    $(".type").hide();
    $(this).next("input").show();
});

Demo: http://jsfiddle.net/JvPYv/1/

tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • @ tymeJV , its not working with complete form, is it possible that we can call it through any id – Syed Sep 16 '13 at 15:24