/    Sign up×
Community /Pin to ProfileBookmark

Setting hidden field’s values

Hi there, new here, so bare with me!

I’ve got a web page where I’d like to set the value of a hidden field after the page has loaded (to the value of user input in an iframe) but when the “save” button is clicked. I’m trying to do it so that when the save button is clicked and the form processed it calls update_hidden_field() which sets the value of the hidden field (called “iframeText”) to the content of the iframe(called “view”).

Here are the critical bits of code:-

[CODE]
<script>
function update_hidden_field() {
iframeText.value = view.document.body.innerHTML;
return true;
}
</script>
….
<form name=”page_editor” METHOD=”POST” action=”/cgi-bin/page_editor/Process_page_editor_form.pl” onsubmit=”return update_hidden_field(this.form)”>

<iframe id=”view” src=”body.html”></iframe>
<input name=”iframeText” type=”hidden” value=””></input>
<input type=”submit” name=”operation” value=”Save”>

[/CODE]

Many thanks in advance for your time and help ?
Scruff

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@efficaciousSep 29.2008 — what exactly is the problem your having?
Copy linkTweet thisAlerts:
@ScruffauthorSep 29.2008 — yeah it would help wouldn't it! lol!

ok in a perl file that I'm using to process the form I want to pass in the value of the iframe via the hidden field called iframeText which I'm trying to set in the function update_hidden_field(). I'm currently displaying an html page of results of various data values to test they're working and the value of iframeText is coming out as blank - as it's originally set to, so it's not being reset to the value of the iframe.
Copy linkTweet thisAlerts:
@efficaciousSep 29.2008 — [CODE]<script>
function update_hidden_field() {
iframeText.value = view.document.body.innerHTML;
return true;
}
</script>[/CODE]


should be:

[CODE]<script>
function update_hidden_field()
{
document.getElementById('iframeText').value=document.getElementById('view').body.innerHTML;
return('true');
}
</script>[/CODE]



try that... its not tested so..
Copy linkTweet thisAlerts:
@ScruffauthorSep 29.2008 — nope no difference...

does an onsubmit need to have a return value? or can I just call the function and it not return anything - I can't see why it needs to in this situation...
×

Success!

Help @Scruff 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.27,
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,
)...