How to add prefix code on change event dropdown












0















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 '18 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 '18 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 '18 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 '18 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 '18 at 18:22
















0















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 '18 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 '18 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 '18 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 '18 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 '18 at 18:22














0












0








0








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 '18 at 7:44









Pathik Vejani

2,86323059




2,86323059










asked Nov 18 '18 at 12:09









Ahma-D-XCVAhma-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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 18:22












0






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',
autoActivateHeartbeat: false,
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

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




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

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Guess what letter conforming each word