gaya Posted February 6, 2013 Share Posted February 6, 2013 Is it possible to have more than one function inside a function. please tell me Link to comment Share on other sites More sharing options...
callumacrae Posted February 6, 2013 Share Posted February 6, 2013 Yes.I don't like writing short replies, but there is seriously nothing more I can say here. Link to comment Share on other sites More sharing options...
gaya Posted February 6, 2013 Author Share Posted February 6, 2013 (edited) ok. Then please tell me. I'm having a form with two buttons. <input type="submit" name="question" id="1" value="question" onclick="reply_click(this.id)" /><input type="submit" name="answer" id="2" value="answer" onclick="reply_click(this.id)" /> I've to write the javascript by checking the conditions for both buttons sepeately in one validate function. Edited February 6, 2013 by gaya Link to comment Share on other sites More sharing options...
callumacrae Posted February 6, 2013 Share Posted February 6, 2013 What specifically is going wrong here? Could you provide a minimal case so that I don't have to work through all your code to find out what the problem is myself. Link to comment Share on other sites More sharing options...
thescientist Posted February 6, 2013 Share Posted February 6, 2013 as replied, what's the problem? Where is your javascript code? What are you stuck on? Link to comment Share on other sites More sharing options...
callumacrae Posted February 6, 2013 Share Posted February 6, 2013 as replied, what's the problem? Where is your javascript code? What are you stuck on?OP originally posted a huge block of code with no whitespace, but has now edited it down to two seemingly irrelevant lines. Link to comment Share on other sites More sharing options...
gaya Posted February 7, 2013 Author Share Posted February 7, 2013 as replied, what's the problem? Where is your javascript code? What are you stuck on?My javascript is function reply_click(clicked_id){alert(clicked_id);var clicked_id=this.id;}function validate(){/*var a=document.getElementById('1').value;alert(a);var b=document.getElementById('2').value;alert(;*/if(clicked_id=="ques"){alert("hai");var quest1=document.getElementById('ques1').value;var board_txt=document.getElementById('board_txt').value;var subject_txt=document.getElementById('subject_txt').value;var cno=document.getElementById('cno').value;var pno=document.getElementById('pno').value;short_type=document.getElementById('short_type');short_type1=short_type.options[short_type.selectedIndex].value;quest1=trim(quest1);board_txt=trim(board_txt);subject_txt=trim(subject_txt);pno=trim(pno);cno=trim(cno);if(quest1==""){alert("Please enter Question");document.getElementById('ques1').focus();return false;}else if (board_txt==""){alert("Please Select Board");document.getElementById('board_txt').focus();return false;}else if (subject_txt==""){alert("Please Select Subject");document.getElementById('subject_txt').focus();return false;}else if( pno==""){alert("Please enter valid Page No");document.getElementById('pno').focus();return false;}else if (cno==""){alert("Please Select Chapter No");document.getElementById('cno').focus();return false;}}else if(clicked_id=="ans"){alert("hhh");var stmt1=document.getElementById('stmt1').value;}} When clicking the answer button it didnt come the elseif condition. Link to comment Share on other sites More sharing options...
Ingolme Posted February 7, 2013 Share Posted February 7, 2013 The variable "clicked_id" is local to the first function, it cannot be accessed from anywhere else but inside the first function. 1 Link to comment Share on other sites More sharing options...
jeffman Posted February 7, 2013 Share Posted February 7, 2013 Also important, you never call the validate function. It has to be called from within reply_click. As it is, all that code does nothing. I don't see why you need the internal function anyway, if that's where most of the code is going to be. BTW, your users are going to hate you for making them sit through a potentially long string of alerts. Changing the innerHTML of a label next to the invalid item, or causing a red dot to appear next to the invalid item, is much more user friendly. Link to comment Share on other sites More sharing options...
callumacrae Posted February 7, 2013 Share Posted February 7, 2013 Also important, you never call the validate function. It has to be called from within reply_click. As it is, all that code does nothing. I don't see why you need the internal function anyway, if that's where most of the code is going to be. BTW, your users are going to hate you for making them sit through a potentially long string of alerts. Changing the innerHTML of a label next to the invalid item, or causing a red dot to appear next to the invalid item, is much more user friendly.It's not a long string of alerts, it's even worse; it is fix one field, get new error message when submitting for, fix the next field, etc. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now