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:

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

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/D_INV_NUO_COLL.do?operation=helpFornitore');return false;" data-padlock="false">
      <span>
        Help</span>
    </a>
  </span>
            <input type="hidden" name="idForn" value="">
            </td>

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.