Hi guys i would like to ask how i can submit in codigniter the other value from html select list to the same column in the data base , for example .
I have this code in Html :
<selectid="major"class="formcontrol"name="f4"onchange='CheckColors(this.value);' required >
<option value="other">other</option>
</select>
<input type="text" name="f4" id="major" style='display:none;'/>
So when i click other another input show up (Javascript) ,
I need the value of the input field to be submit to data base to the same place , and not the value of the select :
And this is my model :
function insert_into_db()
{
$f1 = $_POST['f1'];
$f2 = $_POST['f2'];
$f3 = $_POST['f3'];
$f4 = $_POST['f4'];
$f5 = $_POST['f5'];
$f6 = $_POST['f6'];
$f7 = $_POST['f7'];
$f8 = $_POST['f8'];
$f9 = $_POST['f9'];
$this->db->query("INSERT INTO end VALUES('','$f1','$f2','$f3','$f4','$f5','$f6','$f7','$f8','$f9')");
}
the value f4 , i need to be submit from the select list if its selected , other wise it will be submitted from the input value , please any help ?
It's not recommended to use duplicated name for two separate form elements.
Try to use different name for the select box and the input box. You can still compare the posted values on server and then pick one for storing.
You may have a complicated UI but try not to make the form fields complicated too.
Hope this helps.
all what i made is the flowing in the model :
function insert_into_db() {
$f1 = $_POST['f1'];
$f2 = $_POST['f2'];
$f3 = $_POST['f3'];
$test=$_POST['f4'];
if($test=="other"){
$f4 = $_POST['f5'];
}else{
$f4 = $_POST['f4'];
}
$f6 = $_POST['f6'];
$f7 = $_POST['f7'];
$f8 = $_POST['f8'];
$f9 = $_POST['f9'];
i add variable test="other" then post this value else other value .