Reputation: 20648
Hi I have wrote a method like this and i want to include a condition inside the string passed to the model and my method did not work . How to include an if condition?
$.modal("<div id='edit_user_form' class='user_mange_popup' align='center'>/'if(true){//do something}'/</div>")
Upvotes: 0
Views: 164
Reputation: 150050
If you mean that you want to vary the content of the string depending on some condition you can do something like this:
var modalStr = "<div id='edit_user_form' class='user_mange_popup' align='center'>";
if(yourConditionHere){
modalStr += "some other string to add";
}
modalStr += "</div>";
$.modal(modalStr);
Obviously you can add an else
or as many else if
branches as you like, and concatenate in variables, etc.
Or you can use the ternary conditional operator:
$.modal("<div id='edit_user_form' class='user_mange_popup' align='center'>"
+ (someCondition ? "string to add if true" : "string to add if false")
+ "</div>");
Upvotes: 2
Reputation: 2041
a = "<div id='edit_user_form' class='user_mange_popup' align='center'>"
if (true){
a += something
}
a += </div>
$.modal(a)
dOes this solve your problem ?
Upvotes: 2