Can someone help with the below code how to pre-select as NO from a drop down menu : <select name="article" id="article" onchange="set_article();"> <option value="">Select...</option> <option value="yes"<?php if($row_article["group_name_article"]=="yes"){?>selected="selected"<?php }?>>Yes</option> <option value="no"<?php if($row_article["group_name_article"]=="no"){?>selected="selected"<?php }?>>No</option> </select> Code (markup): Thanks in Advance.
<select name="article" id="article" onchange="set_article();"> <option value="">Select...</option> <option value="yes">Yes</option> <option value="no" selected>No</option> </select>
Sorry ,I am not coder but when I try to save it then the drop down does not get saved into database which is NO in this case . I may need to show all codes for better view as below: Sorry ,I am not coder but when I try to save it then the drop down does not get saved into database which is NO in this case . I may need to show all codes for better view as below: <td width="271" align="right" bgcolor="#CCCCCC" class="login_input"><b>Do you Want to Show Article :</b> </td> <td width="469" colspan="2" bgcolor="#CCCCCC" class="login_input"> <?php $sq_article=mysql_query("select * from campaign where campaign_id='".$_REQUEST["campaign_id"]."'"); $row_article=mysql_fetch_array($sq_article); ?> <select name="article" id="article" onchange="set_article();"> <option value="">Select...</option> <option value="yes"<?php if($row_article["group_name_article"]=="yes"){?>selected="selected"<?php }?>>Yes</option> <option value="no"<?php if($row_article["group_name_article"]=="no"){?>selected="selected"<?php }?>>No</option> </select> </td> </tr> <tr> <td colspan="3" bgcolor="#49A0CD"> <div id="article_container" style="display:<?php if($row_article["group_name_article"]=="yes"){?>block;<?php }else{?>none;<?php }?>"> <table width="744"> <tr> <td width="267" align=""><b>Please Select Your Article Group: </b></td> <td width="465"> <select name="article_tracking" id="article_tracking"> <option value="">Select...</option> <?php $flag1=0; $sq_ar=mysql_query("select * from article where username='".$_SESSION["username_session"]."' group by group_id"); while($sq_row=mysql_fetch_array($sq_ar)) { if($sq_row["article_group_name"]!="") { ?> <option value="<?php echo $sq_row["group_id"];?>"<?php if($row2["article_refer"]==$sq_row["group_id"]){$flag1=1;?>selected="selected"<?php }?>><?php echo $sq_row["article_group_name"];?></option> <?php } } ?> </select> Code (markup):
I think you are missing a space there: It is printing as: <option value="yes"selected="selected">Yes</option> OR row_article["group_name_article"] << on database, what column has "yes" "no" stored? The column name there: "group_name_article" doesn't sound to store "yes/no". Looks like you just copied some code from other line.
Thanks for comment. It does not store yes or no in database column as I do not see there. I have put the code with no space here because I wanted to show the actual code . with the new code ;It is showing NO as pre-selected ,but after saving and return back to edit mode ,it is showing as YES for the selection. I have put the the given code in the file as below with space but no success: <option value="no" selected<?php if($row_article["group_name_article"]=="no"){?>selected="selected"<?php }?>>No</option> Is the above correct input?
If you see this part, this is a column fetched from database and if the value from database it "no" then the select option is selected. But as you stated here, you don't store yes or no, what do you store here?
Thanks for your comment. I was trying to say that I do not see any store from database table when selecting YES or NO . I am storing either of Yes or No from drop down. There is no any selection by default from database. The pre-selected option from menu is Select... Sorry if my description seems nonsense ,I have no clue how this is working. Thanks
<select name="article" id="article" onchange="set_article();"> <option value="">Select...</option> <option value="yes"<?php if($row_article["group_name_article"]=="yes"){?>selected="selected"<?php }?>>Yes</option> <option value="no"<?php if($row_article["group_name_article"]=="no"){?>selected="selected"<?php }?>>No</option> </select> Code (markup): Here if this is the 1st article, it will show "Select..." on the dropdown as selected. If once it is saved, where is it saved? Like you do is set_article() which probably calls to some AJAX request and store it to database. And once that is stored, it needs to remember one of the option. right?[This part is troubling you]. Need few more details to make it clear. Column Names on the table(The column that stores "yes" or "no"). Or the code where set_article() is called that calls the ajax
My apologize ,actually yes you are right. I was mistakenly look at different database table.but now I found out the place where it is saving. It seems the option for Yes and No are stored as Yes or No in a column called group_name_article as it is showing in the code above I sent earlier. Below is the code which I have : Thanks
I'm not even gonna start on how bad it is to store a boolean value in a database as "yes" or "no" (or "Yes" / "No" or any combination thereof...)
Much less if it's only a yes/no, why not use a checkbox which only has yes/no? If it was actually stored in the DB as boolean all you'd need instead of the select is: echo ' <input type="checkbox" name="article" id="article"', $row_article["group_name_article"] ? ' checked' : '', '>'; Code (markup): Instead of wasting a select and multiple options on it. Also, even if you were to use the select, excellent poster child for why it's stupid to do <?php more than once in a file.
You should seperate the attributes. That's what's making it fail. <option value="yes"<?php if($row_article["group_name_article"]=="yes"){?> selected="selected"<?php }?>>Yes</option> <option value="no"<?php if($row_article["group_name_article"]=="no"){?> selected="selected"<?php }?>>No</option>