textarea count commas.

Thread Solved

Join Date: May 2007
Posts: 431
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training
 
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:
  1. <input type="radio" name="radio" value="xxxx" onclick="chgtx2(this.value);" />

And the JavaScript function to something like:
  1. <script language="javascript">
  2. function chgtx2(value)
  3. {
  4. if(value==9.95)
  5. {
  6. window.document.form.hidden1.value=10;
  7. }
  8. else
  9. {
  10. window.document.form.hidden1.value=20;
  11. }
  12. }
  13. </script>
That should do the trick.

And to have the keyword count changed based on the radio button selection, change the JavaScript to:
  1. if(count != parseInt(window.document.form.hidden1.value) - 1) {
  2. alert("Only "+ window.document.form.hidden1.value +" keywords are allowed.");
  3. document.form.textarea1.focus();
  4. return false;
  5. }
  6. else {
  7. return true;
  8. }

And you could add the PHP code into that, like so:
  1. <?php
  2. $error = false; // Used later to print the error message
  3.  
  4. if(isset($_POST['a'])) {
  5. if(substr_count(trim($_POST['a'], ','), ',') != intval($_POST['hidden1']) - 1) {
  6. $error = true;
  7. }
  8. else
  9. {
  10. // Process your keywords here
  11. }
  12. }
  13. ?>
Which I highly recommend, seeing as JavaScript is not really a reliable validation method.
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 957
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark
 
0
  #12
17 Days Ago
Originally Posted by Atli View Post
... JavaScript is not really a reliable validation method.
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.
"...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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 82
Reputation: muralikalpana is an unknown quantity at this point 
Solved Threads: 3
muralikalpana's Avatar
muralikalpana muralikalpana is offline Offline
Junior Poster in Training
 
0
  #13
17 Days Ago
Which I highly recommend, seeing as JavaScript is not really a reliable validation method.
could i know why java script is not reliable validation to compare with php? i will keep in my mind ur valuable suggestions.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 147
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 15
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
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.

Originally Posted by muralikalpana View Post
could i know why java script is not reliable validation to compare with php? i will keep in my mind ur valuable suggestions.
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 82
Reputation: muralikalpana is an unknown quantity at this point 
Solved Threads: 3
muralikalpana's Avatar
muralikalpana muralikalpana is offline Offline
Junior Poster in Training
 
0
  #15
17 Days Ago
i am passing null values for 10 keywords like----- j,j, , ,j,j,j,j,j,j. i think this is also an error. but it does not showing error.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC