开发者

Javascript Form submission: undefined

开发者 https://www.devze.com 2023-02-22 05:42 出处:网络
This must be a simple problem but i can\'t figure out why i开发者_运维技巧t\'s not working. The script shall pass values of the tags field to a script on the same page.

This must be a simple problem but i can't figure out why i开发者_运维技巧t's not working. The script shall pass values of the tags field to a script on the same page.

<FORM id="form" METHOD="" ACTION="#" >
<input size="40" name='tags' id='tags' onSubmit="javascript: submitForm(this)">
<INPUT TYPE="submit" id='q' VALUE="Submit" >
<INPUT TYPE="reset" VALUE="Reset">
</FORM>
<div id='info'>This sentence will be replaced</div>

<script>

var tags;

function submitForm(form)
{
    tags = form.tags.value
    return false ;
}
alert(tags)
...
</script>

alert box says: undefined


You run that alert before running submitForm(). Try moving alert(tags) before return false;, inside submitForm(form).

function submitForm(form)
{
 tags = form.tags.value;
 alert(tags);
 return false ;
}
0

精彩评论

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