1

For some reason that I cannot fathom, the following code does not work:

<!DOCTYPE html>
<html>
<head>
<title>Devit Ajax Test</title>
<script language="JavaScript" type="text/javascript" src="js/voucher.js"></script>
</head>
<body onLoad="document.VU.cellNo.focus()">
<form name="VU" id="VU" method="post" >
    <div class="FormItem">
        <label>Cell Number:</label>
        <input type="tel" id="cellNo" name="cellNo" required > 
    </div>
    <p>
    <div class="FormItem">
        <label>PIN:</label>
        <input id="pin" name="pin" type="text" required >
    </div>
    <div class="FormItem">
        <p> 
        <input type="submit" value="Submit" onclick="submit_click()"> 
        </p>  
    </div>
<center>
<div id="loadingNode"></div>
</center>
</body>
</html>
<script>
function submit_click()
{
    alert("progExe()");
    progExe("http://web.devit.co.za/PEMObi/Pages/HomePage/Homepage.aspx?CellNumber="+VU.cellNo.value"&PIN="+VU.pin.value);    
}
</script>

The submit_click() function never gets called despite the onclick call.

3
  • 1
    Not the reason it doesn't work, but you may want to consider moving your <script> before your </body> or into the <head>, rather than having it completely outside of the <html>. Commented May 27, 2013 at 20:17
  • Did you check your error console? Commented May 27, 2013 at 20:32
  • Out of curiosity, what are the implications of putting a <script> outside the <html> tree? Commented May 27, 2013 at 20:41

3 Answers 3

4

This issue is with the line that calls progExe() -- the string you're building in the function call is missing a plus sign between to parts.

This missing plus sign is a syntax error, and makes it invalid Javascript code. This in turn means that the entire code block is made invalid, which means that the browser won't execute it at all.

To prove this, we can comment out the progExe() line. This will remove the syntax error, and thus the rest of the code will be seen as valid and therefore you will find that the alert() starts working.

Fixing the error of course will also resolve the problem. Add a plus sign after VU.cellNo.value.

It's obvious once you see it, but it is the kind of bug that is easy to miss, and it demonstrates is why it is a good idea to write code using a decent editor. If you open the code in a text editor or IDE with good syntax highlighting features, it will show you exactly where the problem is. Netbeans, for example, will flag the line with an error message. It makes it much easier to find these things.

Sign up to request clarification or add additional context in comments.

Comments

0

You are missing a + in your string in progExe.

progExe("http://web.devit.co.za/PEMObi/Pages/HomePage/Homepage.aspx?CellNumber="+VU.cellNo.value+"&PIN="+VU.pin.value);

Comments

0

You're missing a + in your code:

Change

progExe("http://web.devit.co.za/PEMObi/Pages/HomePage/Homepage.aspx?CellNumber="+VU.cellNo.value"&PIN="+VU.pin.value);  

to

progExe("http://web.devit.co.za/PEMObi/Pages/HomePage/Homepage.aspx?CellNumber="+VU.cellNo.value+"&PIN="+VU.pin.value);  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.