user1121210
user1121210

Reputation: 83

how to assign value to textbox usingJavascript/ jquery when texbox is not having id?

Here is sample HTML code

<input name="DPAAP" type="hidden" value="Estambul Turquía - Todos los aeropuertos (IST)">
<input type="hidden" name="acArrValues" value="IST|Todos los aeropuertos|Estambul||Turquía|TR|110TR-010041.0138428.94966">

I can not change HTML code . How shall I assign another value to above textbox using Javascript/jquery

Upvotes: 0

Views: 61

Answers (3)

Aleksei Pugachev
Aleksei Pugachev

Reputation: 286

With Javascript:

document.getElementsByName("DPAAP")[0].value = "your value";

With jQuery:

 $('input[name="DPAAP"]').val('your value');

Upvotes: 0

Saravana
Saravana

Reputation: 40642

You can select it by the name:

$('input[name="DPAAP"]').val('Your value');

But you have to make sure there are not inputs with the same name.

Upvotes: 1

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

try this:

$('input[name="DPAAP"]').val('whatyouwant');

or if you want the second change try this:

$('input[name="acArrValues"]').val('whatyouwant');

Obviously you on't have multiple input with that name and if you have to change it when the page is loaded and not when for example click on a buottn you need to include the code inside $(document).ready() like this:

$(document).ready(function(){
    $('input[name="DPAAP"]').val('whatyouwant');
    $('input[name="acArrValues"]').val('whatyouwant');
});

Upvotes: 2

Related Questions