Jump to content

WillUK

Members
  • Posts

    17
  • Joined

  • Last visited

Everything posted by WillUK

  1. <HTML> <head> <title>Exam entry</title> <script language="javascript" type="text/javascript"> function validateForm() { var result = true; var msg=""; if (document.ExamEntry.name.value=="") { msg+="You must enter your name \n"; document.ExamEntry.name.focus(); document.getElementById('name').style.color="red"; result = false; } if (document.ExamEntry.subject.value=="") { msg+=”You must enter the subject \n"; document.ExamEntry.subject.focus(); document.getElementById('subject').style.color="red"; result = false; } if(msg==""){ return result; } { alert(msg) return result; } } </script> </head> <body> <h1>Exam Entry Form</h1> <form name=”ExamEntry" method="post" action="success.asp"> <table width="50%" border="0"> <tr> <td id="name">Name</td> <td><input type="text" name="name" /></td> </tr> <tr> <td id="subject">Subject</td> <td><input type="text" name="subject" /></td> </tr> <tr> <td><input type="submit" name="Submit" value="Submit" onclick="return validateForm();" /></td> <td><input type="reset" name="Reset" value="Reset" /></td> </tr> </table> </form> </body> </html> Hi, I am new to JavaScript and am trying to apply the above form validation code. Would an experienced JavaScript developer please take a look and let me know why it is not processing? Am I missing some code? Calling it incorrectly? I appreciate that this is pretty basic stuff but it is driving me nuts! Info: success.asp does not yet exist. Any help would be really appreciated. Thanks Will
  2. Thanks Haku - I considered your approach, but wouldn't I need to somehow apply an ID to it in order to be able to call it from inside the html? At the moment I've got in my html file: (This is in the head section) <script type="text/javascript" language="Javascript" src="javascript/cookie.js"> </script> Then just above the closing body tag: <div id="gas"> </div> Are you saying that I don't need to assign an id?
  3. Hi I have recently taken up Javascript after a couple of years away from coding, so am finding this pretty tough to get my head around. What I am trying to do is to set up the Google Analytics tracking code in an external Javascript file. I do not want the analytics code to be outputted/set on the page unless the user chooses to accept it (This is relating to recent changes to the cookie legislation.). If the user does not choose to accept Analytics, the script runs without setting the analytics code. I decided to use an event handler to deal with this, and I have stored the anlaytics code itself in a function, which is then passed to another function - disp_confirm() - in order for it to have an id applied to it. The plan then is to call this id (and therefore call the event handler) from the just above the closing body tag in the html page (I decided against putting the analytics code in the header because I was under the impression that the event handlers wouldn't process successfully if the code was implemented here). The problem is, I don't know whether this will work, or if I am trying to do something that cannot be done with Javascript. The idea of passing a function to another function doesn't sit well with me - so I'm sure I must be way off the mark with this....I'm not sure if I'm using the correct syntax to pass one function to another either Anyway, here's my code. I'd really appreciate some advice on this, especially if I am way off mark with my approach!! Thanks window.onload = disp_confirm; function disp_confirm() { var r=confirm("This website uses Google Analytics to monitor website use which helps us offer a better service to you. However, No personal data is stored. If you wish to proceed with cookies, click ok. Alternatively click cancel.") if (r==true) { var gas = passString.analytics(); document.getElementById('gas'); } else { alert("Google cookies have been disabled") } } function analytics() { var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXX-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); }); } Any help advice would be really appreciated.... Thanks
  4. Hi MattyB I have a very similar problem. I am pulling 'categories' from a database e.g. sport, current affairs etc etc. Each category is then listed individually as a link. When the user clicks a category link, the user is redirected to a page: blog.php . blog.php then displays all the threads for that particular category. Well that's what should happen anyway - I just can't figure out how to store the category id and then communicate that info to the seperate blog.php file. I thought that storing the data using sessions might be a way forward, but that proved to be a dead end. The session data was stroring category info, but the same category id was being strored irrespective of the category selection being made i.e. the user selects 'current affairs' but the displayed data is 'sport'; the user selects 'politics, but the displayed data is 'sport' etc etc So, I'm a bit stuck too. If I manage to find a solution I will post it back in here: but at least you know you are not alone!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.