I am trying to pass parameters from a PHP to a JavaScript, and this is the way I do this:
my php file:
<div>
<textarea name="text" cols="80" rows="2">
<?= $note['note'] ?>
</textarea>
<p type="hidden" name="request_id" value="<?= $request_id ?>" >
<p type="hidden" name="cve" value="<?= $cve ?>" >
<p type="hidden" name="note_id" value="<?= $note['note_id'] ?>" >
<p type="hidden" name="status" value="<?= $note['status'] ?>" >
<button class="add-note">Save</button>
</div>
My JavaScript function:
$(function() {
$(".add-note").click(function(){
tr = $(this).parent();
tds = tr.children();
note = $(tds[0]).text();
request_id = $(tds[1]).value;
cve = $(tds[2]).value;
note_id = $(tds[3]).value;
status = $(tds[4]).value;
alert(note);
});
});
The result is I get the value Save when I get the text of note, that is, the text of the buttom itself, instead of the text placed in the textarea. I get nothing for the rest of the values.
I wanted to approach this with a classic form, but the thing is that I need the current value of a textarea, that why I am using JavaScript, but I am not accessing properly to the HTML elements...
Thank you very much.
ptags are unclosed, so this must create the wrong structure. I also think you want to replace theptags with<input type="hidden" />...valueofpwouldn't work like that, with theinputit does. I also used.val()for extracting the text of thetextareaelement and it works perfectly ;)