javascript - in my form I checked input radio and image changes, but I fill input text and the image changes back -


okey, here goes big problem:

i have form, has submit button enables when have checked , filled both inputs (there no problem that). if follow these steps, realize problem is:

  1. load jsfiddle https://jsfiddle.net/ozlmdx4o/ don't pay attention code now, @ form: there default profile image, empty input text, unchecked input radio, , disabled submit button.
  2. test form: fill input text , check input radio , observe how default profile image changes image. check , uncheck input radio observe how image linked input. key of this.
  3. but, if input text filled wrong? delete whatever entered in input text , start on again... but...what? image has returned default profile image! if linked input radio! why???

why happens? can check code, because there must somewhere have missed. can me keep image linked input radio button? input radio button unchecked = default profile image. input radio button checked = special image.

//input radio on & off code var prv1; var markit1 = function(e) {   if (prv1 === && this.checked) {     this.checked = false;     prv1 = null;    } else {     prv1 = this;   }   checkifvalid();   if (!e.target.checked) {     var img = document.getelementbyid('theimage');     img.src = 'https://s17.postimg.org/7gc66bzu7/user.jpg';   } }; //turn on , off functions $(function() {   $('input.whatever_class').on('click', markit1);        $('input[type=text]').on('keyup', markit1); }); var sbmtbtn = document.getelementbyid('submitbutton'); sbmtbtn.disabled = true; //change images  function changeimage(imgname) {      image = document.getelementbyid('theimage');      image.src = imgname;   }  function checkifvalid() {   var current = $('input[type=radio]:checked');  if ((current.length >= 1) && ($('input[type=text]').val() != "")) {     sbmtbtn.disabled = false;   } else {     sbmtbtn.disabled = true;   } }; 

i image not change anytime modify input text. can fix code necessary solve problem?

thanks!

add check:

if (!e.target.checked && !document.getelementbyid('whatever_id').checked) {   var img = document.getelementbyid('theimage');   img.src = 'https://s17.postimg.org/7gc66bzu7/user.jpg'; } 

it running check function on input text , not getting checked , hence problem. hope helps.

ps: have kept e.target.checked if not required can remove it.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -