0

here is the function from inside a script

function dosubmit()
  {
    if (getObj("Frm_Username").value == "")
    {
      getObj("errmsg").innerHTML = "Username cannot be empty.";
      getObj("myLayer").style.visibility = "visible" ;
      return;
    }
    else
    {
      getObj("LoginId").disabled = true;
      getObj("Frm_Logintoken").value = "3";
      document.fLogin.submit();
    }
  }

i want to get the value of getObj("Frm_Logintoken") as i can't pull the value from #Frm_Logintoken

using document.getElementById("#Frm_Logintoken") this gives me null

because Frm_Logintoken only gets it's value when i click submit .

<input type="hidden" name="Frm_Logintoken" id="Frm_Logintoken" value="">

full page code

i found this online /getObj\("Frm_Logintoken"\).value = "(.*)";/g but when i run it ... it gives me the same line again ! it's full code https://hastebin.com/gurosatuna.xml

mina nageh
  • 143
  • 2
  • 2
  • 13

1 Answers1

0

First:

Your checking if a value is empty with JS. However this is NOT needed as HTML does this for you. Add a attribute required and the form will not submit as long this value is empty

Documentation: https://www.w3schools.com/tags/att_input_required.asp

Second:

You could use the event handler 'on submit'. The code is not complete enough to know if u did this but I suppose you just added a Click handler on the button.

Documentation: https://www.w3schools.com/jsref/event_onsubmit.asp

When combining these two, you always have a username filled in and the code only executes when submitted. I hope this helps, if not please leave a comment and I will edit this answer.

EDIT: the answer on this SO will also help (not the checked on but the one below)

How can I listen to the form submit event in javascript?

Wimanicesir
  • 4,606
  • 2
  • 11
  • 30
  • "Add a attribute required and the form will not submit as long this value is empty" it's already there !! but document.fLogin.submit(); refreshes the page and there is a lock after 3 wrong tries ... and it's not just like clicking the button as it just shows the pop up of Username cannot be empty. .... about the second part i don't own the code it's an already written code so i don't know if editing the code after the page loads helps ... – mina nageh Jun 07 '19 at 15:36
  • hi would this help ? https://gist.github.com/ali-essam/80b58ea170051a96108b5f320754564f – mina nageh Jun 07 '19 at 17:23