javascript - How can I insert ternary operation in 4th parameter in form_dropdown function in codeigniter?

367

I want my javascript onchange function not to be called whenever my$at_row[0]->ID is true. The javascript onchange function call was placed in my form_dropdown function. I have tried my code but it wasn't working at all and prompts errors. How could I do this right? Here is my code.

Working code

 <?php echo form_dropdown('at[brgy1]',$dropdown_brgy1,(isset($at_row[0]->ID)) ? $at_row[0]->brgy1 : '',"id=brgy_id_1 class=form-control style=width:300px  onchange=javascript:change_barangay_2(); "); ?>

Not working code

<?php echo form_dropdown('at[brgy1]',$dropdown_brgy1,(isset($at_row[0]->ID)) ? $at_row[0]->brgy1 : '',"id=brgy_id_1 class=form-control style=width:300px  "(isset($at_row[0]->ID)) ? return false : "onchange=javascript:change_barangay_2()";"    "); ?>
772

Answer

Solution:

You are using ternary operator wrongly, thereturn false doesn't make any sense the current context, you just have to put empty string"" instead so that if condition expression is true, nothing will be appended to the string.

here is the statement that should work.

<?php echo form_dropdown('at[brgy1]',$dropdown_brgy1,(isset($at_row[0]->ID)) ? $at_row[0]->brgy1 : '',"id=brgy_id_1 class=form-control style=width:300px  "(isset($at_row[0]->ID)) ? "" : "onchange=javascript:change_barangay_2();"); ?>

People are also looking for solutions to the problem: Ajax PHP HTML Form

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.