开发者

How do you write strings to the middle of a web page?

I'm trying to have users enter info into a form (via radio buttons), manipulate the input data, and write resulting text onto the middle of a web page--beneath the radio buttoned form. So I have variables assigned to whenever a user selects a radio button, the onClick event calling a function something like:

function saveValue1(value) {
someVariable=value;<br>
}

And when users click a Submit button, a function works like it's supposed to, ultimately writing an output string. The problem is how to write the string value in the middle of the page. I have this [pseudo]code at the end of the function (preten开发者_开发技巧d the string I want to write to the page is named aVariable):

document.getElementById('aPlace').innerHTML=aVariable;

And of course there's HTML in the displayed page like this:

<div id="aPlace"></div>

After a user pressed the form's Submit button the correct output variable is displayed very briefly, and then disappears. Why is this? And how should I be writing this code instead?

Thanks for helping a newbie, as always.


The form is probably submitted. put a "return false" at the end to stop it submitting the form


It seems that the browser is refreshing? How is the form data handled? If the form is needed only to add the text to the page, I would add a button

<button onclick="saveValue1("+value+");")>

and avoid submitting the form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜