MyBB Community Forums

Full Version: Some help with javascript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,
I need a bit of help with some javascript. Basically i am learning it and am trying to make a small thing which has a text box and when you click the submit button it relaces a div with what you entered into the text box. I can get this to work but the problem is that it only appears for a second?
Any help would be great, Thanks.
Ps. Here's my code.

<script type="text/javascript">
function updatediv(){
var content = document.input.name.value;
document.getElementById('divtoupdate').innerHTML = content;
}
</script>
      <form name="input" onsubmit="updatediv();" method="post">
        Enter your name: 
        <input type="text" name="name" size="30">
        <input type="submit" value="Submit">
      </form></p>
<div id="divtoupdate"></div>
I think you need to return false in the onsubmit event, otherwise the form is being submitted.

<script type="text/javascript">
function updatediv(){
var content = document.input.name.value;
document.getElementById('divtoupdate').innerHTML = content;
return false;
}
</script>
      <form name="input" onsubmit="return updatediv();" method="post">
        Enter your name:
        <input type="text" name="name" size="30">
        <input type="submit" value="Submit">
      </form></p>
<div id="divtoupdate"></div>
Thanks Zinga, You rock Toungue It worked Smile
I need some help too
I have a quck edit like mybb's but when the text is really big it doesnt do anything Sad
How do i encode the data so when send it would update it no matter the size?
I send the text with the POST method and get it with the GET method
There's a encodeURIComponent / escape functions which URL encode text.
Didnt really get that
And there is another problem
It doesnt show cyrillic(cuz the form itself is in the js)