2

here is the function from the source code

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

another regular expression i found but don't even know how to use it

Example of a regular expression to search: before_egrep='N1:getObj("Frm_Logintoken").value = "(\w+)"'

Here, N1 is assigned the value of the back reference - the expression in parentheses. \w + denotes the main compound characters, this is a synonym for "[_[:alnum:]]". Once again - pay attention to the brackets - this is the back link. At the same time, there are also parentheses in the source code fragment - they need to be escaped

i am trying to make an auto login script that works in the background like it

doesn't show the user the login form page but the only the page after it

and i have found this code online too but don't know what's about it contains xhr .

the line that Attracted my attention is

/getObj\("Frm_Logintoken"\).value = "(.*)";/g 

when i run it ... it gives me the line again !

some notes :

i have tried document.getElementById("Frm_Logintoken").value but it gives me empty "" because

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

the page will not even accept the correct password if the Frm_Logintoken token value isn't the same as one in the page.

the Frm_Logintoken is a token generated by the page and it basically increment by one on each successful login.

mina nageh
  • 143
  • 1
  • 2
  • 10

2 Answers2

0

I'm not so sure about suggestion of an expression for helping or ameliorating to help solving your problem, yet if we wish to extract certain attributes and values from the proposed input tag, we would be likely starting with an expression similar to:

name="(.+?)"|id="(.+?)"|value="(.+)?"

which uses alternation to simultaneously collect values of certain attributes, if so would be desired.

Demo

RegEx

If this expression wasn't desired and you wish to modify it, please visit this link at regex101.com.

RegEx Circuit

jex.im visualizes regular expressions:

enter image description here

Community
  • 1
  • 1
Emma
  • 1
  • 9
  • 28
  • 53
  • 1
    thanks but i don't want the value from the input tag but from the function dosubmit() tag – mina nageh Jun 08 '19 at 03:26
  • 1
    this line exactly `getObj("Frm_Logintoken").value = "3";` – mina nageh Jun 08 '19 at 03:28
  • 1
    Wouldn't this just match all the lines that doesn't contain new lines ? any way can we get a one to match this `getObj("Frm_Logintoken").value = "3";` ? – mina nageh Jun 08 '19 at 03:57
  • 1
    i found that `getObj\("Frm_Logintoken"\).value = "(.*)";` works as expected but how can i get the value of the result group 1 ? – mina nageh Jun 08 '19 at 04:41
0

To get your value you might use a capturing group ([^"]+) and a negated character class:

\bgetObj\("Frm_Logintoken"\)\.value = "([^"]+)";

Regex demo | Javascript demo

For example:

let str = `getObj("Frm_Logintoken").value = "3";`;
let pattern =/\bgetObj\("Frm_Logintoken"\)\.value = "([^"]+)";/;

console.log(str.match(pattern)[1]); //3
The fourth bird
  • 96,715
  • 14
  • 35
  • 52
  • your answer is good but i think i asked the wrong question ... i need to make an auto login script so i need the script to find the value for me .. so let str isn't possible in my case ! what should the title of my question be ? – mina nageh Jun 09 '19 at 08:14
  • @minanageh Not sure where your jacascript is located but perhaps you could check [this page](https://stackoverflow.com/questions/1367587/how-do-i-get-the-html-source-from-the-page) to get the html of the current page instead of `let str`. – The fourth bird Jun 09 '19 at 09:14
  • ok i will check it .. my java script should be located on a local web server with the ip of something just like 192.168.1.22 – mina nageh Jun 09 '19 at 10:41
  • i got how to make it work if it's the same page `let str = document.documentElement.innerHTML` then your code `let pattern =/\bgetObj\("Frm_Logintoken"\)\.value = "([^"]+)";/;` `console.log(str.match(pattern)[1]);` but if it's from another page ? – mina nageh Jun 09 '19 at 11:42
  • That depends where that page is. If it is on the same domain and allowed you might try an asynchronous call to get the page and get that html. – The fourth bird Jun 09 '19 at 11:54
  • it's not the same range of ips – mina nageh Jun 09 '19 at 12:18
  • how can i do an asynchronous call ? – mina nageh Jun 09 '19 at 12:19
  • You could check [this page](https://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery) on how to do that. – The fourth bird Jun 09 '19 at 12:31
  • mate i tried this code cause the one in that link isn't clear enough !. ` ` but it doesn't work cause the it page code didn't change with the new code ! – mina nageh Jun 09 '19 at 12:51
  • ` ` tried this from your link doesn't work ! – mina nageh Jun 09 '19 at 13:00
  • ` ` i got the working one but . has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. – mina nageh Jun 09 '19 at 13:29
  • That is what I meant with if it is allowed. You can find resources online how you might enable that also if you are allowed. – The fourth bird Jun 09 '19 at 13:50
  • but the response of the page doesn't have any thing about Access-Control-Allow-Origin !!! what about the object type is there any to get the value using it ? – mina nageh Jun 09 '19 at 14:46