Jump to content

javascript


gaya

Recommended Posts

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 by gaya
Link to comment
Share on other sites

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...