/    Sign up×
Community /Pin to ProfileBookmark

CreateElement javascript

Hi there

I have a requirement to create a new element span or para in a page USING JAVASCRIPT. Had it been the same page where I run the javascript to create the span element .I could have used CreateElement() method. But I need to create an element in a different page. Is it possible through CreateElement() ? or is there any other way to accomplish this? Kindly let me know how this can be done..

To be precise the requirement is similiar to when we send any mail from gmail ..it reverts to inbox page with a message “mail sent successfully” .I want achieve the same on submitting a form, the request is processed and while displaying the result I should display the message.

?

Any help is much appreciated …thanks in advance

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@felgallOct 27.2008 — If the other page is already loaded and from your domain then you just need to reference the window or frame it is in by name on the front of the document.createElement command. If it isn't from the same domain then JavaScript can't access it.
Copy linkTweet thisAlerts:
@saechiraauthorOct 27.2008 — thanks much for the reply, I am using window.location.href=link to redirect the page. In this case , the page is in the domain and page is loaded into the same window.

how can refer to it.


thank you.
Copy linkTweet thisAlerts:
@toicontienOct 27.2008 — Are you using frames, or are you completely reloading the window?
window.frames.[I]frame_name[/I].document.createElement("span");
Copy linkTweet thisAlerts:
@saechiraauthorOct 27.2008 — Hi,

I am not using frames.I am just completing reload the window. By the way a small question here. Is there any way to capture the refresh event in javascript
Copy linkTweet thisAlerts:
@toicontienOct 27.2008 — I think some older browsers had an onreload event you can tap into, though I'm not sure if newer browsers do. So when the same page reloads, you want to create an element? I get the sense a different workflow might be what you want, rather than the onreload event. Can you explain more about what you're trying to do?
Copy linkTweet thisAlerts:
@saechiraauthorOct 28.2008 — Hi thanks for the reply. As explained earlier my purpose is, on successul submission of a form (page1) redirect to another page (say link)and display a message "submitted successfully". I want to add an element to the new page to which the page has been redirected using javascript. I want to do this dynamically using javascript in page1 rather than link page. I dont want to check for conditions and add the script in link page. Is there any way to get this done. Create elemens in a different page.

Also another problem I am facing is the form is resubmitted on every refresh which inturn inserts duplicate records into my table. Any idea how do we avoid this?
Copy linkTweet thisAlerts:
@toicontienOct 28.2008 — ... I dont want to check for conditions and add the script in link page. Is there any way to get this done. Create elemens in a different page. ...[/QUOTE]
No. There is no way to do that. You must put the logic on the different page. When the form submits, you could run a JavaScript that sets a cookie. On the "different" page, you could search for that cookie. If the cookie exists, then append the new element, but the logic for this [I]must[/I] exist on the different page.

But thinking about this more, there [I]might[/I] be a way to do precisely this, if you pardon me thinking while I'm typing. Give the FORM a target:
<form ... [B]target="form_results"[/B]>
When the form submits, open a new window, and pass "form_results" as the window's target name. The window.open function returns a reference to the opened window. Make sure you capture this with a variable:
var resultsWindow = window.open("#", "form_results", "OPTIONS_HERE");
Make sure [B]resultsWindow[/B] is a global variable.

Give the new window an onload event hander:
resultsWindow.onload = function() {
// Create new element and append it here
};


Now when the form submits, it submits to the opened window. When that window finishes loading, a new element will be appended to the opened window.

... Also another problem I am facing is the form is resubmitted on every refresh which inturn inserts duplicate records into my table. Any idea how do we avoid this?[/QUOTE]
Depending on the server side language you use, remove the $_POST data when the page refreshes, after you've inserted the data into the database.
×

Success!

Help @saechira 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.24,
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,
)...