简体   繁体   中英

Passing values as arguments of a function defined in onchange() event

I want to pass a value as an argument of a function. The function is defined on onchange() of a text field. I am using the following code..I use zend form to create the element.

$filedName = "cust_attr_".($i+1);
$fieldArr[$i]       =   $this->createElement('Text',$filedName)
-> setAttrib('class','k-textbox float_left input_width_295 k-invalid')
-> setAttrib('onchange','validateDataType('.$customerAttributes[$i]['data_type'].')')
-> setAttrib('maxlength','14')
-> setAttrib('tabindex',(++$tabStart));

And when i run the code i am getting the value as the argument of function..Like

onchange="validateDataType(A)"

But i am getting an error Uncaught ReferenceError: A is not defined

How to solve this???

"A" should be passed as a string. Without the quotes it looks for A as an object.

-> setAttrib('onchange','validateDataType("'.$customerAttributes[$i]['data_type'].'")')

You will need to change onchange="validateDataType(A)" to single quotes... onchange='validateDataType("A")'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM