View Full Version : Obtain a variable and use it

12-21-2010, 10:07 PM

I'm looking for some guidance for the following problem.

I want to submit a form but it requires a code that is generated by every session (not the php session type). What i'm looking for is for a piece of code that fetch the session code and set it as a variable that can be called in JS.

I know that exists in PHP the cURL that it's able to retrieve the code and set it but i don't know how to start...

rnd me
12-21-2010, 10:32 PM
use ajax to fetch the url that contains the code.
then, search the response using regexp or dom methods.

for example, i recently moved an old-school form to an ajax form, but needed a dynamic id to prevent the submitted form from being rejected.

ajax callback snip to update hard-coded form with remote value:

document.getElementsByName("XID")[0].value=x.responseText.match(/name="XID" value="([\w]+)"/)[1];

in that case, i was matching an input on the remote "real" page that was coded like:

<input type="hidden" name="XID" value="f2090eeb9ccccfb00714e2d377ff5a7d4127b618" />

01-21-2011, 12:52 PM

I understand the concept of ajax but my programming skills are 0 in the matter.

Is it possible for you to provide a more complete example in how should i implement it.

Thanks for your time

rnd me
01-21-2011, 07:58 PM
post the code you are using and i'll see if i can make it work.

01-22-2011, 01:01 AM

The site is something like the example below

What i want is to obtain the value from the page and set it as a variable in my page
<input name="code" type="hidden" id="code" value="1b3f3988e4f45ac005f9e3951d0335f9" />

Using the snip you provided will be
document.getElementsByName("code")[0].value=x.responseText.match(/name="code" value="([\w]+)"/)[1];

If you can help me out i think i need more info about the first 2 steps you mention in your previous post

Thanks for all the help

01-24-2011, 01:37 PM

If you can help me out i think i need more info about the first 2 steps you mention in your previous post

In how to make the request in ajax, obtain the html tag and retrieve to my page...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum