kony Posted January 27, 2007 Share Posted January 27, 2007 echo "<html><script type='javascript'>function check(){card_no = document.form.card_no.value;if(card_no.value.length < 16){alert('card value blank');return false;}if(name==""){alert('enter your name');return false;}if(exp_date==""){alert('card value blank');return false;}}</script><body>";echo "<form name=form method='POST' action='?'>";echo "Name ";echo "<input type='text' name='name' size='20'><br>";echo "Card No. ";echo "<input type='text' name='card_no' size='20'><br>";echo "Expiry Date ";echo "<input type='text' name='exp_date' size='20'><br>";echo "CVV ";echo "<input type='text' name='cvv' size='20'><br>";echo "Amount ";echo "<input type='text' name='amt' size='20'><br>";echo "<input type='submit' name='confirm' value='Confirm' onclick='return check();'>";echo "<input type='reset' name='reset'>";echo "</form>";echo "</body></html>"; Quote Link to comment https://forums.phpfreaks.com/topic/35942-solved-error-else-part/ Share on other sites More sharing options...
Tyche Posted January 27, 2007 Share Posted January 27, 2007 You haven't posted exactly what the problem is, but the first statement in your code won't work as you are not escaping the double quotes within the string - try putting \ before the internal " as below [code]echo "<html><script type='javascript'>function check(){card_no = document.form.card_no.value;if(card_no.value.length < 16){alert('card value blank');return false;}if(name==\"\"){alert('enter your name');return false;}if(exp_date\"\"){alert('card value blank');return false;}}</script><body>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35942-solved-error-else-part/#findComment-170444 Share on other sites More sharing options...
wildteen88 Posted January 27, 2007 Share Posted January 27, 2007 Sooo... Whats wrong? What the code supposed to do, what is happening etc. Do not just post code post an explanation aswell. Also post any errors you are getting in full here too. Quote Link to comment https://forums.phpfreaks.com/topic/35942-solved-error-else-part/#findComment-170445 Share on other sites More sharing options...
kony Posted January 27, 2007 Author Share Posted January 27, 2007 echo "<html><script type='text/javascript'>function check(){len = document.form.card_no.value.lengthcard=document.form.card_no.valuen=0if(len != 16 && len != 15){alert('Enter valid card value');return false;} var cardNo = document.form.card_no.value var cardexp = /^[0-9]{13,19}$/; if (!cardexp.exec(cardNo)) { alert('enter number only'); return false; }if(document.form.name.value.length < 1){alert('enter ur name');return false;}if(document.form.exp_date.value.length < 4){alert('enter expiry date');return false;}}</script><body>";echo "<form name=form method='POST' action='?'>";echo "Name ";echo "<input type='text' name='name' size='20'><br>";echo "Card No. ";echo "<input type='text' name='card_no' size='20'><br>";echo "Expiry Date ";echo "<input type='text' name='exp_date' size='20'><br>";echo "CVV ";echo "<input type='text' name='cvv' size='20'><br>";echo "Amount ";echo "<input type='text' name='amt' size='20'><br>";echo "<input type='submit' name='confirm' value='Confirm' onclick='return check();'>";echo "<input type='reset' name='reset'>";echo "</form>";echo "</body></html>";if(isset($_POST['confirm'])){$name = $_POST['name'];$card_no = $_POST['card_no'];$exp = $_POST['exp_date'];$cvv = $_POST['cvv'];$amount = $_POST['amt'];---code---}javascript does not run! it has no effect on the form. it is suppose to validate the form fields. Quote Link to comment https://forums.phpfreaks.com/topic/35942-solved-error-else-part/#findComment-170453 Share on other sites More sharing options...
sayedsohail Posted January 27, 2007 Share Posted January 27, 2007 I would try something like this?> // untag php than plain html<input type='submit' name='confirm' value='Confirm' onclick='return check();'><input type='reset' name='reset'><?php // tag php Infact you can use this in your form, it won't do any harm. Quote Link to comment https://forums.phpfreaks.com/topic/35942-solved-error-else-part/#findComment-170459 Share on other sites More sharing options...
wildteen88 Posted January 27, 2007 Share Posted January 27, 2007 If you are echo'ing large amounts of HTML (including Javascript and CSS) use [url=http://uk2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc]herdoc syntax[/url]Also rather than alerti'ing one error message at a time, show all the errors on big alert box. I have done this for you.[code]<?phpecho <<<HTML<html><head><script type="text/javascript">function check() { var error = new Array(); var error_msg = ""; var frm = document.getElementById("form"); if(frm.name.value == "") { error[0] = "Eenter your Name"; } if(frm.card_no.value.length < 16) { error[1] = "Card No. left blank or is invalid"; } if(frm.exp_date.value == ""){ error[2] = "Card expirary date left blank"; } if(error.length > 0) { for(i = 0; i <= (error.length)-1; i++) { if(error[i] && error[i] != "") { error_msg += "\\t- " + error[i] + "\\n"; } } alert("Please fix the following errors:\\n\\n" + error_msg); return false; } else { return true; }}</script></head><body><form id="form" method="POST" action="?passed=true" onSubmit="return check();"> Name: <input type="text" name="name" size="20"><br /> Card No.: <input type="text" name="card_no" size="16"><br /> Expiry Date: <input type="text" name="exp_date" size="20"><br /> CVV: <input type="text" name="cvv" size="20"><br /> Amount: <input type="text" name="amt" size="20"><br /> <input type="submit" name="confirm" value="Confirm"> <input type="reset" name="reset"></form></body></html>HTML;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35942-solved-error-else-part/#findComment-170462 Share on other sites More sharing options...
kony Posted January 29, 2007 Author Share Posted January 29, 2007 thanks wildteen88 , it works!! Quote Link to comment https://forums.phpfreaks.com/topic/35942-solved-error-else-part/#findComment-171719 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.