0
 <button type="button" id="btn_select_tahsilat1" class="btn btn-success"
                            style="                                                       
                            onclick="select_id(  <?= $d2['mellicode'] ?> )">

  </button>

my question is: while mellicode with example values "034" post to funtion select_id in below , that value is "34" how keep zero in frist char?

function select_id(mellicode) {
alert(mellicode);
mgh
  • 1
  • 1
  • Does this answer your question? [Javascript 0 in beginning of number](https://stackoverflow.com/questions/35047982/javascript-0-in-beginning-of-number) – D. Pardal Apr 04 '21 at 21:54
  • Duplicate of [How do I pass variables and data from PHP to JavaScript?](https://stackoverflow.com/q/23740548/4642212). `select_id(= $d2['mellicode'] ?>)` is absolutely not guaranteed to work. JSON-encode your PHP value, then JSON-decode it in JS. – Sebastian Simon Apr 04 '21 at 21:58
  • Also, inline event handlers like `onclick` are [not recommended](https://stackoverflow.com/q/11737873/4642212). They are an [obsolete, hard-to-maintain and unintuitive](https://stackoverflow.com/a/43459991/4642212) way of registering events. Always [use `addEventListener`](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#inline_event_handlers_%E2%80%94_dont_use_these) instead. – Sebastian Simon Apr 04 '21 at 21:59

1 Answers1

0

Your number is potentially being treated as octal, although that behaviour may be browser specific. In any event, the leading zero will not be preserved.

You will either have to do without the leading zero, or pass your parameters as strings.

Try to set argument between Single quotes onclick="select_id('Your Argument Number')

Like this:

function select_id(mellicode) {
      alert(mellicode);
}
<button type="button"   onclick="select_id(  '034' )"  >Click </button>