call javascript function in php and pass php variables? -


say have 3 variables, id, name, number, on php script, $name, $number, $id

on php, create button

    print "<td><form><input type='button' name='edit' id='edit' onclick=ed($name, $number, $id) value='edit' /></td>"; 

i want 3 variables sent javascript.

the function call seems work fine if use

onclick=ed(this.id) 

and modify function header, , passes string "edit" that's not quite useful.

function header in javascript is

function ed(name, number, id) { //stuff here } 

for whatever it's worth using code gets me error on html, unexpected } on line2 of html document.

edit:i should clarify said code gives me errors didn't "well use this!" when expected not work.

using this:

<input type='button' id='$id' onclick=ed(this.id) value='edit' /> 

allows me send value in $id javascript function because saved in id field. along lines i'm hoping for, i'm unable find if there's way that. edit: 3 variables.

edit again:

using:

<form><input type='button' name='$name' id='$id' title='$number' onclick='ed(this.name,this.title,this.id)' value='edit' /></form> 

sent values of 3 php variables javascript function.

it's not pretty, works.

for custom attributes define data-attributes, e.g. shown on mozilla dev:

<div id="user" data-id="1234567890" data-user="johndoe" data-date-of-birth>john doe </div>  var el = document.queryselector('#user');  // el.id == 'user' // el.dataset.id === '1234567890' // el.dataset.user === 'johndoe' // el.dataset.dateofbirth === ''  el.dataset.dateofbirth = '1960-10-03'; // set dob.  // 'somedataattr' in el.dataset === false  el.dataset.somedataattr = 'mydata'; // 'somedataattr' in el.dataset === true 

in case, seems need data-number other 2 standard properties of dom-element.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -