I’m new in PHP and im using CI 😀
Now i have a view user_form_v and its controller user
in my controller i tried to pass a string variable name $validate and i will validate it in my view with javascript, so if $validate == add i will enable my input text.
This is my javascript(NOT WORKING) :
<script type="text/javascript">
function validation(){
var temp = <?php echo $validate?>
if (temp == "add")document.getElementById("id").disable = false;
}
</script>
and this is my input text, the default is DISABLED :
<input id="id" type="text" name="ID_user" class="text" disabled="disable"
value="<?php echo (isset($user['ID_user']))?$user['ID_user']:""?>"/>
ANSWER :
According to the choosen answer, Javascript is no needed here(sorry im a noob) so all we need to do is add this : <?php if($validate!='add'){echo "disabled";} ?> this way, my input text will be disabled if they choose update.
However it cant be work with disabled="disabled"(I dont know why)
So this is the final code for dynamic input text : <input type="text" name="ID_user" class="text"
<?php if($validate!='add'){echo "disabled";} ?>
value="<?php echo (isset($user['ID_user']))?$user['ID_user']:""?>"/>
In your javascript:
.disablednot.disablevalidation()? If not, this code will never execute.In your html:
disabled="disabled"notdisabled="disable"Update after your comments:
Are you sure there is even a need for javascript here at all? I mean, you seem to be allowing the client to make decisions that the server would be happy to do.
<input id="id" type="text" name="ID_user" class="text" value="<?= $user['ID_user']?>" <? if($validate!=='add'){echo "disabled";} ?>/>And scrap the javascript all together. (I dropped your
isset()call, throw it back in if you really need it)