Skip to content
Advertisement

<input type="text" assign id value to php string

I have a modal form to write employee working time stamp to an SQL database. I select the employee from a dropdown menù and fill by javascript function the name and surname input box using the id tag. When I submit the form, the datas are written into the db using php. The problem is I’m not able to convert javascript string to php string or assign the id tag of the input tag to a php string. I know that writing inside the input I can assign the value with php value=”….”.

JavaScript

not works

Here the code

JavaScript

I receive the following errors/notice: Notice: Undefined index: nome and Notice: Undefined index: cognome

Advertisement

Answer

You are using .innerHTML to assign values to your input but here id="nome" is use two place for div and input same for cognome .So, .innerHTML remove input-box inside the div and replace it with new texts that’s the reason when you submit your form you get undefined index error because there is no inputs exists with the required value .

Instead , use .value to assign value to input and remove .readOnly = false attribute before adding and after adding use .readOnly = true.

Demo Code :

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement