开发者

Starting Javascript

a couple of questions (never done javascript before). Below is part of the what happens on submit, what is something, the action, the php script its sent to?

Also is there any 开发者_StackOverflow社区software you guys reccomend for checking you're javascript, like the equivalent of an ide? im using notepad++.

Is the rest the right sort of idea? I'm using several else ifs for each method, checking valid == true.

<SCRIPT LANGUAGE="JavaScript">

<form action="something" onsubmit="return ok()">

function ok() {

    if (validate_Info() == false)   
    {
        alert('Please enter a name');

        return false;
    }
else if

else if


Yes, the action attribute in the form tag is the URL that the form will be sent to.

You are using some pretty old example code, the language attribute has been deprecated for a long time. Here is an example that is more up to date with current coding standards:

<script type="text/javascript">

function validate() {
  if (!validate_Info()) {
    alert('Please enter a name');
    return false;
  }
  if (!validate_SomeOtherField()) {
    alert('Please enter some other information');
    return false;
  }
  return true;
}

</script>

<form action="something" onsubmit="return validate();">

As you see, there is no need to use an else at all. As you are returning from inside the if statement, the else is pointless.


The form is submit to the URL contained in the action attribute of the form element.

javascript ide-wise I recommend aptana studio.

multiple if statements should be used if you have multiple different cases. It seems you only have 2 (valid, not valid), so a simple if-else will suffice.

if you're just starting javascript, I definitely recommend javascript: the definitive guide by O'reilly. :D

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜