JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
document.form.input.value not staying Posted by smokeys_13 on 12 Sept 2009 at 12:23 PM
Hey, I've used the document.value command/script loads in previous sessions, but I can't see what is going on with this one.

##In the head section inside a <script> tag###

function submit_wepname()
{
document.info_gather.weapon_name.value = preset_wepnames.dropdown_wep_choice.value;
}



##In the body section##

<form id="info_gather" name="info_gather" method="post" action="">
<input type="text" id="weapon_name" name="weapon_name" value="test1" readonly="readonly"/>
<input type="text" id="attack_type" name="attack_type" value="test2" readonly="readonly"/>
</form>


When the javascript function is run (via a submit button) it works and the input value in the form changes to the appropriate value, but it then instantly flicks back to the default value (test1). Even if i put value="" it just flicks back to an empty input box. Any ideas? I'm guessing it's a simple thing that I'm gonna kick myself about =/
Report
Re: document.form.input.value not staying Posted by mac_doggie on 2 Dec 2009 at 1:30 PM
You'd better not post the form but instead just do your actions in the onclick of a normal button or link. If you submit your form it is seen as new request. The page resets itself (unless your browser saved the values of your input fields)

just do something like <a href="javascript:submit_wepname()">do it</a>

-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.