joomla.dev250
joomla.dev250

Reputation: 11

jquery code under hidden input field is not work when we get it using jquery

I have added the field and their jquery code to get the value for that field like

<input type='hidden' name="test" id="test" value="data=$('#response').val()">

I am getting that hidden field value in jquery and splitting it by '=' but when I alert the value it shows the $('#response').val() i am expecting it to return the value of the response field type.

var val = $("#test").val();
var arr1 = val.split('=');

alert(arr1[1]);

return => $('#response').val()

expected => value of responce field.

please let me know what i am doing wrong.

Upvotes: 0

Views: 34

Answers (1)

john Smith
john Smith

Reputation: 17906

in the value attribute there will be no javascript executed, it just contains the value of the input, see https://www.w3schools.com/tags/att_value.asp or compare to onclick attribute for example. There might be some parsing with alert, but it´s general knowledge not to debug any js with alerts.

you can just set the value attribute with javascript though

below your relevant markup you could do:

$('#test').val( $('#response').val() ); // will set the value

var expected = $('#test').val(); // will output the desired value then

Upvotes: 0

Related Questions