I am doing my code in php. For setting focus in textbox i did it. But by clicking add button the focus gets to another empty textbox. The first textbox entered element is not shown and again by clicking add button the focus is again come to the first textbox itself. pls tell me, why its like this.any1 please help me.
By textbox I assume you mean a TEXTAREA tag. By "add button" I assume you mean some client side scripting like JavaScript? Really not sure I'm grasping what you are trying to say -- ranguage rarrier and so forth -- but really without seeing the code you are using it's impossible to diagnose what you even mean, much less what you want.
The following is the code, whai i did. <html> <head> <title> Fill Up </title> </head> <body> <form name="Fillup" action="fill.php" method="post"> <table border='1' align="center"> <tr> <td><b>QNo</b></td><td>: <input type="text" name="QNo"></td> </tr> <tr> <td><b>Question1</b></td><td>: <input type="text" name="Quest1" id="quest1"></td> </tr> <tr> <td><b>Question2</b></td><td>: <input type="text" name="Quest2" id="quest2"></td> </tr> <tr> <td><b>Option1</b></td><td>: <input type="text" name="Opt1" id="opt1"></td> </tr> <tr> <td><b>Option2</b></td><td>: <input type="text" name="Opt2" id="opt2"></td> </tr> <tr> <td><b>Option3</b></td><td>: <input type="text" name="Opt3" id="opt3"></td> </tr> <tr> <td><b>Option4</b></td><td>: <input type="text" name="Opt4" id="opt4"></td> </tr> <tr> <td><b>CorrectNo</b></td><td>: <input type="text" name="CNo" id="cno"></td> </tr> <tr> <td><b>QuesWav</b></td><td>: <input type="file" name="browse" id="browse"></td> </tr> <tr> <td><b>QuesImg</b></td><td>: <input type="file" name="browse" id="browse"></td> </tr> <tr> <td><b>PageNo</b></td><td>: <input type="text" name="PgNo" id="pgno"></td> </tr> <tr> <td><b>Chapter</b></td><td>: <input type="text" name="Chapter" id="chapter"></td> </tr> <tr> <td><b>Year</b></td><td>: <input type="text" name="Year" id="year"></td> </tr> <tr> <td><b>Board</b></td><td>: <input type="text" name="board"></td> </tr> <tr> <td><b>Subject</b></td><td>: <input type="text" name="subject"></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="add" value="Add"> <input type="reset" value="clear"> </td> </tr> </table> </form> <?php include("config.php"); $ques1=$_POST['Quest1']; $ques2=$_POST['Quest2']; $option1=$_POST['Opt1']; $option2=$_POST['Opt2']; $option3=$_POST['Opt3']; $option4=$_POST['Opt4']; $correctno=$_POST['CNo']; $pageno=$_POST['PgNo']; $sub=$_POST['add']; if(isset($sub) && $sub="Add") { if($ques1=="" && $ques2=="") { echo "<script>alert('enter the question'); document.Fillup.Quest1.focus();</script>"; } else if(($ques1!="" || $ques2!="") && $option1=="") { echo "<script>alert('question entered'); alert('enter the option'); document.Fillup.Opt1.focus();</script>"; } else if($correctno=="") { echo "<script>alert('enterthe correctno'); document.Fillup.CNo.focus();</script>"; } else if($correctno=="1" && $pageno=="") { echo "<script>alert('entered option is correct');alert('enter the pageno'); document.Fillup.PgNo.focus();</script>"; } else if($correctno=="2") { echo "<script>alert('enter the correct option'); document.Fillup.Opt2.focus();</script>"; } else if($correctno=="3") { echo "<script>alert('the entered option is incorrect'); document.Fillup.Opt3.focus();</script>"; } else if($correctno=="4") { echo "<script>alert('enter the option'); document.Fillup.Opt4.focus();</script>"; } } ?> </body> </html> Code (markup):
1) Why is that a table? 2) Where are your labels and fieldsets? 3) if it WAS a table you should be using TH instead of TD+B 4) You seem to be using this oddball mix of client side and server side code for... well... I'm not even sure why. Is that some form of attempt at submit validation or something?!? Of course, I wouldn't waste memory making copies of your $_POST values for no good reason... It looks to me like you're trying to use client side scripting to process something that should be handled server-side when you output the form... of course i have no idea what your 'Fillup' method is supposed to do... referring to elements by their 'name' is outdated Netscape 4 style... I've no clue why you're sending alerts when you resend the form instead of just say... colorizing the invalid element and showing text below it. I'm not sure what it is you're trying to accomplish, but it's a laundry list of how not to build a form or create user interaction for it. You've got 15 year out of date markup with pointlessly bloated PHP to do... well, I'm not even sure...