/    Sign up×
Community /Pin to ProfileBookmark

working with IFrame and javascript

Hello,

I have a main.html with hyperlinks, IFrameand “onload function” in it.
The hyperlinks and the onload function, are working as described:

When “onload” or onClick (on the hyperLink) event occured, a javascript
functions is called – it switches the Iframe src (each event has different src)
and make submit():

The code:
document.forms[0].action = switchToFileName ;
document.forms[0].submit();

My problem is:
After I am switching the first time – to one of the sources of the hyperlinks (after the file was onload ones), the onload function is been called again –
and call the src of the onload functions.

Why its happens? Why it returns to load the orginal page?

More details:
1.My onload code:
<body onload=”init(‘<%=System.currentTimeMillis()%>’);”>
<form name=”hndlr” action=”” method=”post” target=”_HNDLR”>

  • 2. The Iframe code:
    <iframe id=”_HNDLR” name=”_HNDLR” src=”” style=”width:0;height:0;”></iframe>
    Tnx
  • to post a comment
    JavaScript

    5 Comments(s)

    Copy linkTweet thisAlerts:
    @FangNov 25.2007 — Submitting the form reloads the document.
    Copy linkTweet thisAlerts:
    @KissingerauthorNov 25.2007 — when I am calling to other src, it doesnt reload the document:

    This is the main.html (part of it):

    <td>

    <select name="states" id="states" WIDTH="200" STYLE="width: 200px" onChange="updateByStates(this.options.selectedIndex);">

    <option value="">---Show State---</option></select></td>

    This is the javascript function:

    document.forms[0].action = "selectsHndlr.jsp";

    document.forms[0].submit();

    Here it doesnt load the document object again.

    Only when I call to other jsp source.
    Copy linkTweet thisAlerts:
    @FangNov 25.2007 — The document containing the select and JavaScript will reload the document.

    If any other frame is involved please show the complete document.
    Copy linkTweet thisAlerts:
    @KissingerauthorNov 25.2007 — The select box is in the main.html.

    When onClick event is occured the "updateByStates" func is been called.

    Inside this func, this code is done:

    document.forms[0].action = "selectsHndlr.jsp";

    document.forms[0].submit();

    and it works ok.

    But, when the submit button is pressed, I am switching the source of the Iframe again:

    document.forms[0].action = "getTic.jsp";

    document.forms[0].submit();

    And the next time I am trying to switch - from getTic.jsp - it returns to the

    main.html, and activate the onLoad()

    Why is that?
    Copy linkTweet thisAlerts:
    @FangNov 25.2007 — As I wrote the document is reloaded when you submit, unless it is prevented.
    &lt;select name="states" id="states" WIDTH="200" STYLE="width: 200px" onChange="[COLOR="Green"]return[/COLOR] updateByStates(this.options.selectedIndex);"&gt;
    and updateByStates(idx) {
    [I]iframeName[/I].location='getTic.jsp'; // the idx value?
    [COLOR="Green"]return false;[/COLOR]
    }

    The return(s) prevent the real submission occurring.
    ×

    Success!

    Help @Kissinger spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.15,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...