How to add prefix code on change event dropdown











up vote
0
down vote

favorite












Hi I'm new in codeigniter so this is the problem



I want to add prefix to textbox based on selected value in dropdown menu here's the source



In Controller



function index(){
$data['title'] = 'SIPPERTIKOMPPAK|Input Barang';
$data2 =array(
'kode_barang' => $this->m_master->kode_barang(),
'get_lokasi' => $this->m_master->get_lokasi(),
'get_jenis' => $this->m_master->get_jenis()
);

$this->load->view('backend/preload/meta',$data);
$this->load->view('backend/preload/head');
$this->load->view('backend/preload/sidebar');
$this->load->view('backend/master/v_masterb',($data2));
}


In Model



function kode_barang(){
$kode= $this->db->select_max('id_barang')->get('tb_master_barang')->result_array();
$qkode = array();
foreach($kode as $r) {
$qkode = $r['id_barang']+1;
}
$qkode=str_pad($qkode,3, '0' , STR_PAD_LEFT);
// $qqkode = 'PRINJ'.$qkode;
return $qkode;
}


In View



<div class="form-group">
<label for="kode_barang">Kode Barang</label>
<input type="text" class="form-control" name="kode_barang" value="<?php echo $kode_barang; ?>" readonly />
</div>
<div class="form-group">
<label for="get_jenis">Jenis Barang</label>
<?php echo form_dropdown('id_jenis', $get_jenis, '', 'class="form-control"');?>
</div>


I want to add prefix to textbox for example like this



if id_jenis ==1
textbox.value = 'Prefix'+($qkode value from model)
else
textbox.value = 'Prefix'+($qkode value from model)









share|improve this question
























  • If I'm understanding this correctly your kode_barang input field has a value like stmt and you want when you change id_jenis dropdown for the kode_barang input value to change to prefix stmt?
    – Alex
    Nov 19 at 0:37










  • yes something like that for example if I change id_jenis dropdown == 1 then in kode_barang input field will change to PRINJ001 and if I change it to id_jenis == 2 then in kode_barang input field will change to PC001 something like that
    – Ahma-D-XCV
    Nov 19 at 2:01










  • sounds like you want to change the prefix not suffix as your question suggests. where is PRIN and PC coming from? is that the dropdown item name? further where is 001 coming from?
    – Alex
    Nov 19 at 7:33










  • Dropdown is list of item group like printer, pc, hdd, LCD, LED, etc and I want in kode_barahg textbox value to change according to the group chosen from dropdown menu for example if user choose PC then in textbox value change to PC001 and 001 come from select max query from one of the table which name is tb_master_barang in the database
    – Ahma-D-XCV
    Nov 22 at 14:13










  • sounds like you'll need ajax as kode_barang is dependent/needs to be fetched based on the dropdown. do a simple onchange jquery selector.
    – Alex
    Nov 22 at 18:22















up vote
0
down vote

favorite












Hi I'm new in codeigniter so this is the problem



I want to add prefix to textbox based on selected value in dropdown menu here's the source



In Controller



function index(){
$data['title'] = 'SIPPERTIKOMPPAK|Input Barang';
$data2 =array(
'kode_barang' => $this->m_master->kode_barang(),
'get_lokasi' => $this->m_master->get_lokasi(),
'get_jenis' => $this->m_master->get_jenis()
);

$this->load->view('backend/preload/meta',$data);
$this->load->view('backend/preload/head');
$this->load->view('backend/preload/sidebar');
$this->load->view('backend/master/v_masterb',($data2));
}


In Model



function kode_barang(){
$kode= $this->db->select_max('id_barang')->get('tb_master_barang')->result_array();
$qkode = array();
foreach($kode as $r) {
$qkode = $r['id_barang']+1;
}
$qkode=str_pad($qkode,3, '0' , STR_PAD_LEFT);
// $qqkode = 'PRINJ'.$qkode;
return $qkode;
}


In View



<div class="form-group">
<label for="kode_barang">Kode Barang</label>
<input type="text" class="form-control" name="kode_barang" value="<?php echo $kode_barang; ?>" readonly />
</div>
<div class="form-group">
<label for="get_jenis">Jenis Barang</label>
<?php echo form_dropdown('id_jenis', $get_jenis, '', 'class="form-control"');?>
</div>


I want to add prefix to textbox for example like this



if id_jenis ==1
textbox.value = 'Prefix'+($qkode value from model)
else
textbox.value = 'Prefix'+($qkode value from model)









share|improve this question
























  • If I'm understanding this correctly your kode_barang input field has a value like stmt and you want when you change id_jenis dropdown for the kode_barang input value to change to prefix stmt?
    – Alex
    Nov 19 at 0:37










  • yes something like that for example if I change id_jenis dropdown == 1 then in kode_barang input field will change to PRINJ001 and if I change it to id_jenis == 2 then in kode_barang input field will change to PC001 something like that
    – Ahma-D-XCV
    Nov 19 at 2:01










  • sounds like you want to change the prefix not suffix as your question suggests. where is PRIN and PC coming from? is that the dropdown item name? further where is 001 coming from?
    – Alex
    Nov 19 at 7:33










  • Dropdown is list of item group like printer, pc, hdd, LCD, LED, etc and I want in kode_barahg textbox value to change according to the group chosen from dropdown menu for example if user choose PC then in textbox value change to PC001 and 001 come from select max query from one of the table which name is tb_master_barang in the database
    – Ahma-D-XCV
    Nov 22 at 14:13










  • sounds like you'll need ajax as kode_barang is dependent/needs to be fetched based on the dropdown. do a simple onchange jquery selector.
    – Alex
    Nov 22 at 18:22













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Hi I'm new in codeigniter so this is the problem



I want to add prefix to textbox based on selected value in dropdown menu here's the source



In Controller



function index(){
$data['title'] = 'SIPPERTIKOMPPAK|Input Barang';
$data2 =array(
'kode_barang' => $this->m_master->kode_barang(),
'get_lokasi' => $this->m_master->get_lokasi(),
'get_jenis' => $this->m_master->get_jenis()
);

$this->load->view('backend/preload/meta',$data);
$this->load->view('backend/preload/head');
$this->load->view('backend/preload/sidebar');
$this->load->view('backend/master/v_masterb',($data2));
}


In Model



function kode_barang(){
$kode= $this->db->select_max('id_barang')->get('tb_master_barang')->result_array();
$qkode = array();
foreach($kode as $r) {
$qkode = $r['id_barang']+1;
}
$qkode=str_pad($qkode,3, '0' , STR_PAD_LEFT);
// $qqkode = 'PRINJ'.$qkode;
return $qkode;
}


In View



<div class="form-group">
<label for="kode_barang">Kode Barang</label>
<input type="text" class="form-control" name="kode_barang" value="<?php echo $kode_barang; ?>" readonly />
</div>
<div class="form-group">
<label for="get_jenis">Jenis Barang</label>
<?php echo form_dropdown('id_jenis', $get_jenis, '', 'class="form-control"');?>
</div>


I want to add prefix to textbox for example like this



if id_jenis ==1
textbox.value = 'Prefix'+($qkode value from model)
else
textbox.value = 'Prefix'+($qkode value from model)









share|improve this question















Hi I'm new in codeigniter so this is the problem



I want to add prefix to textbox based on selected value in dropdown menu here's the source



In Controller



function index(){
$data['title'] = 'SIPPERTIKOMPPAK|Input Barang';
$data2 =array(
'kode_barang' => $this->m_master->kode_barang(),
'get_lokasi' => $this->m_master->get_lokasi(),
'get_jenis' => $this->m_master->get_jenis()
);

$this->load->view('backend/preload/meta',$data);
$this->load->view('backend/preload/head');
$this->load->view('backend/preload/sidebar');
$this->load->view('backend/master/v_masterb',($data2));
}


In Model



function kode_barang(){
$kode= $this->db->select_max('id_barang')->get('tb_master_barang')->result_array();
$qkode = array();
foreach($kode as $r) {
$qkode = $r['id_barang']+1;
}
$qkode=str_pad($qkode,3, '0' , STR_PAD_LEFT);
// $qqkode = 'PRINJ'.$qkode;
return $qkode;
}


In View



<div class="form-group">
<label for="kode_barang">Kode Barang</label>
<input type="text" class="form-control" name="kode_barang" value="<?php echo $kode_barang; ?>" readonly />
</div>
<div class="form-group">
<label for="get_jenis">Jenis Barang</label>
<?php echo form_dropdown('id_jenis', $get_jenis, '', 'class="form-control"');?>
</div>


I want to add prefix to textbox for example like this



if id_jenis ==1
textbox.value = 'Prefix'+($qkode value from model)
else
textbox.value = 'Prefix'+($qkode value from model)






codeigniter dropdown onchange prefix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 7:44









Pathik Vejani

2,86622958




2,86622958










asked Nov 18 at 12:09









Ahma-D-XCV

1




1












  • If I'm understanding this correctly your kode_barang input field has a value like stmt and you want when you change id_jenis dropdown for the kode_barang input value to change to prefix stmt?
    – Alex
    Nov 19 at 0:37










  • yes something like that for example if I change id_jenis dropdown == 1 then in kode_barang input field will change to PRINJ001 and if I change it to id_jenis == 2 then in kode_barang input field will change to PC001 something like that
    – Ahma-D-XCV
    Nov 19 at 2:01










  • sounds like you want to change the prefix not suffix as your question suggests. where is PRIN and PC coming from? is that the dropdown item name? further where is 001 coming from?
    – Alex
    Nov 19 at 7:33










  • Dropdown is list of item group like printer, pc, hdd, LCD, LED, etc and I want in kode_barahg textbox value to change according to the group chosen from dropdown menu for example if user choose PC then in textbox value change to PC001 and 001 come from select max query from one of the table which name is tb_master_barang in the database
    – Ahma-D-XCV
    Nov 22 at 14:13










  • sounds like you'll need ajax as kode_barang is dependent/needs to be fetched based on the dropdown. do a simple onchange jquery selector.
    – Alex
    Nov 22 at 18:22


















  • If I'm understanding this correctly your kode_barang input field has a value like stmt and you want when you change id_jenis dropdown for the kode_barang input value to change to prefix stmt?
    – Alex
    Nov 19 at 0:37










  • yes something like that for example if I change id_jenis dropdown == 1 then in kode_barang input field will change to PRINJ001 and if I change it to id_jenis == 2 then in kode_barang input field will change to PC001 something like that
    – Ahma-D-XCV
    Nov 19 at 2:01










  • sounds like you want to change the prefix not suffix as your question suggests. where is PRIN and PC coming from? is that the dropdown item name? further where is 001 coming from?
    – Alex
    Nov 19 at 7:33










  • Dropdown is list of item group like printer, pc, hdd, LCD, LED, etc and I want in kode_barahg textbox value to change according to the group chosen from dropdown menu for example if user choose PC then in textbox value change to PC001 and 001 come from select max query from one of the table which name is tb_master_barang in the database
    – Ahma-D-XCV
    Nov 22 at 14:13










  • sounds like you'll need ajax as kode_barang is dependent/needs to be fetched based on the dropdown. do a simple onchange jquery selector.
    – Alex
    Nov 22 at 18:22
















If I'm understanding this correctly your kode_barang input field has a value like stmt and you want when you change id_jenis dropdown for the kode_barang input value to change to prefix stmt?
– Alex
Nov 19 at 0:37




If I'm understanding this correctly your kode_barang input field has a value like stmt and you want when you change id_jenis dropdown for the kode_barang input value to change to prefix stmt?
– Alex
Nov 19 at 0:37












yes something like that for example if I change id_jenis dropdown == 1 then in kode_barang input field will change to PRINJ001 and if I change it to id_jenis == 2 then in kode_barang input field will change to PC001 something like that
– Ahma-D-XCV
Nov 19 at 2:01




yes something like that for example if I change id_jenis dropdown == 1 then in kode_barang input field will change to PRINJ001 and if I change it to id_jenis == 2 then in kode_barang input field will change to PC001 something like that
– Ahma-D-XCV
Nov 19 at 2:01












sounds like you want to change the prefix not suffix as your question suggests. where is PRIN and PC coming from? is that the dropdown item name? further where is 001 coming from?
– Alex
Nov 19 at 7:33




sounds like you want to change the prefix not suffix as your question suggests. where is PRIN and PC coming from? is that the dropdown item name? further where is 001 coming from?
– Alex
Nov 19 at 7:33












Dropdown is list of item group like printer, pc, hdd, LCD, LED, etc and I want in kode_barahg textbox value to change according to the group chosen from dropdown menu for example if user choose PC then in textbox value change to PC001 and 001 come from select max query from one of the table which name is tb_master_barang in the database
– Ahma-D-XCV
Nov 22 at 14:13




Dropdown is list of item group like printer, pc, hdd, LCD, LED, etc and I want in kode_barahg textbox value to change according to the group chosen from dropdown menu for example if user choose PC then in textbox value change to PC001 and 001 come from select max query from one of the table which name is tb_master_barang in the database
– Ahma-D-XCV
Nov 22 at 14:13












sounds like you'll need ajax as kode_barang is dependent/needs to be fetched based on the dropdown. do a simple onchange jquery selector.
– Alex
Nov 22 at 18:22




sounds like you'll need ajax as kode_barang is dependent/needs to be fetched based on the dropdown. do a simple onchange jquery selector.
– Alex
Nov 22 at 18:22

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360702%2fhow-to-add-prefix-code-on-change-event-dropdown%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360702%2fhow-to-add-prefix-code-on-change-event-dropdown%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy