Javascript not getting value of input field

Hi, from this page (uploaded, the original page is protected), I’m trying with a userscript to set the value “Leggere” in Fornitore field (left side one) if empty, but the script isn’t working and nothing is entered.

This is the userscript I’m using:

setme = document.querySelector('input[name="cdFornitore"]');
if (setme.value === "") {setme.value="Leggere"};

This is the original code of the field:

<td colspan="4" class=" ">
              <input type="text" name="cdFornitore" value="" maxlength="10" onchange="getFornitoreInve();">
              <input type="text" name="nome" value="" maxlength="160" style="width:65%">
            <span id="hForn">
              <a title="" class="button input-help grid-1" draggable="false" href="javascript:;" onclick="Next.submit(FormDet,'/sebina/catalogazione/');return false;" data-padlock="false">
            <input type="hidden" name="idForn" value="">

Thank you!

You have onchange="getFornitoreInve() but I see no function named getFornitoreInve. What am I missing?

Why don’t you use getElementsByName() ?

Thanks, Thallius. This works:

setme = document.getElementsByName("cdFornitore")[0]
if (setme.value === "") {setme.value="Leggere"};

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.