Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#32 Extracting data from pages with js

open
nobody
5
2005-05-05
2005-05-05
No

Hi,

this lib is very usefull. However i have a little
problem extracting data from a page with uses js. So
how can i simulate a click on a submit button ?

Discussion

  • Derrick Oswald
    Derrick Oswald
    2005-05-06

    Logged In: YES
    user_id=605407

    A form using JavaScript is very similar to one using a plain
    form, but you have to decipher the script to know what's
    happening. I can't.

    For example, the SourceForge site has this javascript for
    the 'My Favorites' drop down:
    <script language="JavaScript" type="text/javascript">
    <!--
    function jump(targ,selObj,restore){ //v3.0
    if (selObj.options[selObj.selectedIndex].value)

    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
    }
    //-->
    </script>

    If you look at the form using this script (with extraneous
    stuff removed):

    <form action="/my/favorite_redirect.php" method="POST">
    <select name="navmenu" onChange="jump('parent',this,1)"
    class="smfc0b">
    <option value="">My Favorites</option>
    <option value="/">SF.net Home</option>
    <option value="/projects/htmlparser/">htmlparser</option>
    etc...
    </select>
    <input type="image" border="0" name="Submit" value="GO"
    alt="Go" width="30" height="20"
    src="https://images-ssl.sourceforge.net/images/go.gif" >
    </form>

    This tells me that when you click on the drop down, the
    value of the menu item (option), is used to form the url, so
    for the htmlparser item:

    onChange ('parent', this, 1)
    ->
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    -> eval (parent.location='/projects/htmlparser/')

    This would submit the form to
    "http://sourceforge.net//my/favorite_redirect.php" using
    POST with:
    location='/projects/htmlparser/'
    navmenu=""
    Submit="GO"

    An example of using post for a form is provided on the Wiki,
    (if somebody hasn't trashed it recently):
    http://htmlparser.sourceforge.net/wiki/index.php/PostOperation