| | |
textarea count commas.
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
1
#11 17 Days Ago
IDs of elements don't work like the names of input elements. If you have two elements with the same ID, only one of them will be used by JavaScript. (The last one, I believe.)
So you need to rethink your approach.
A simple workaround is to have the elements pass their value into the function as a parameter and have the function use that.
Meaning, you would have to change both the radio buttons to:
And the JavaScript function to something like:
That should do the trick.
And to have the keyword count changed based on the radio button selection, change the JavaScript to:
And you could add the PHP code into that, like so:
Which I highly recommend, seeing as JavaScript is not really a reliable validation method.
So you need to rethink your approach.
A simple workaround is to have the elements pass their value into the function as a parameter and have the function use that.
Meaning, you would have to change both the radio buttons to:
html Syntax (Toggle Plain Text)
<input type="radio" name="radio" value="xxxx" onclick="chgtx2(this.value);" />
And the JavaScript function to something like:
javascript Syntax (Toggle Plain Text)
<script language="javascript"> function chgtx2(value) { if(value==9.95) { window.document.form.hidden1.value=10; } else { window.document.form.hidden1.value=20; } } </script>
And to have the keyword count changed based on the radio button selection, change the JavaScript to:
javascript Syntax (Toggle Plain Text)
if(count != parseInt(window.document.form.hidden1.value) - 1) { alert("Only "+ window.document.form.hidden1.value +" keywords are allowed."); document.form.textarea1.focus(); return false; } else { return true; }
And you could add the PHP code into that, like so:
php Syntax (Toggle Plain Text)
<?php $error = false; // Used later to print the error message if(isset($_POST['a'])) { if(substr_count(trim($_POST['a'], ','), ',') != intval($_POST['hidden1']) - 1) { $error = true; } else { // Process your keywords here } } ?>
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
0
#12 17 Days Ago
Ditto.
Client side validation is only ever useful to prevent MOST users from sending wrong data to the server MOST of the time. It will not prevent certain individuals from bypassing these checks (intentionally or otherwise) and you can guarantee that at some point "tainted data" will reach your server. Anyone with a webpage can send data via 'dummy form' to your form handling page.
Nasties could be in the shape of SQL/script injection - not nice.
Client side validation is only ever useful to prevent MOST users from sending wrong data to the server MOST of the time. It will not prevent certain individuals from bypassing these checks (intentionally or otherwise) and you can guarantee that at some point "tainted data" will reach your server. Anyone with a webpage can send data via 'dummy form' to your form handling page.
Nasties could be in the shape of SQL/script injection - not nice.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
1
#14 17 Days Ago
Thats simply because javascript can perform only client side validation... a nasty user can disable javascript for his/her browser and can easily surpass ur validation script.
But php validation is done at server end which is impossible for a user to disable coz its out of his/her reach.
The reason we use javascript is to do some basic validations to avoid user sending data to server and then getting rejected from server validation which will eat up much of server's resources.
In a nutshell javascript can enhance ur validation process but can never replace server side validation(PHP in this case).
Hope i made my point clear.
But php validation is done at server end which is impossible for a user to disable coz its out of his/her reach.
The reason we use javascript is to do some basic validations to avoid user sending data to server and then getting rejected from server validation which will eat up much of server's resources.
In a nutshell javascript can enhance ur validation process but can never replace server side validation(PHP in this case).
Hope i made my point clear.
Last edited by venkat0904; 17 Days Ago at 1:30 am.
Gimme reputation points if u find my post helpful.
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
![]() |
Similar Threads
- radiobutton with textarea (PHP)
- Some help (counting lines from an input file) (C++)
- SELECT into TEXTAREA (PHP)
- how to format the form textarea? (PHP)
- how to delete extra commas on csv file with php (PHP)
- Need Help with TextArea and Loop (Java)
- Count/Find in const char * (C++)
- Java Program Help (Java)
- Word and Letter Count (C)
Other Threads in the PHP Forum
- Previous Thread: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
- Next Thread: Fatal error: Class 'cite' not found
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





