PDA

View Full Version : basic javascript question



badperson
February 17th, 2011, 04:53 PM
Hi,
I have this little test function:



function testSetValue(id){

document.getElementById(id).value = 'what???';

}


here's the html:



<form id="entryInputForm">
<textarea name="text" id="entryInputArea" rows="20" cols="105" > </textarea><br/>
<input type="submit" value="hello!" onClick="testSetValue('entryInputArea')"/>

</form>



that code sets the value, but then the text immediately disappears. (I'm setting the value of a textarea)

anyone know what causes that?
bp

StephenDavison
February 17th, 2011, 05:37 PM
Try changing your button from type="submit" to type="button". I think the submit button is triggering a form submission that is reloading your page as the default action. The content of the text is being reset when the page reloads.

badperson
February 17th, 2011, 05:49 PM
gotcha...that worked. thanks!