I'm trying to do a very simple task but for some reason I can't do it.
basically I am using the if statement to change the value of an input field using javascript but it doesn't work!
this is my code:
if (document.getElementById("colour").value == "171515"){
document.getElementById("colour").value = "db0000";
}
if (document.getElementById("colour").value == "db0000"){
document.getElementById("colour").value = "171515";
}
and the HTML looks like this:
<input type="text" id="colour" name="colour" class="colour" value="171515"/>
so what i need to do is this:
I launch a page and the input field is on my page with the value of value="171515", and then I press a button and that should change the value of the input field to value="db0000", and then I press the button again, and it should change the value of the input button to value="171515" and I need to do the same steps as many times as I want.
currently, it seems like it gets into a loop action and thats why it doesn't change the value of input field! (correct me if i'm wrong).
any help would be appreciated.
Thanks
EDIT:
The javascript code above is executed like so:
$(params.addPplTrigger).bind('click', function(e){
e.preventDefault();
///////// THE CODE ABOBE WILL GO HERE///////////
}
ifs, one changes the value one way, the other changes it back. Useif (condition) {...} else if (condition) {...}or a simpleif (condition) {...} else {...}.