Jump to content

Recommended Posts

Hi to all,

 

    how can, show and hide the textbox depending on the selection of the radio buttons and validating the textbox.

<script language="javascript">

function showHide(value)

{

if(value=='show')

{

document.getElementById('emailid').style.display='';

}

else

{

document.getElementById('emailid').style.display='none';

}

 

if(value=='hide')

{

document.getElementById('emailid').style.display='none';

}

else

{

document.getElementById('emailid').style.display='';

}

}

 

</script>

<input type="radio" id="selectemailid" name="emailid" value="<?php echo $_POST['email'] ?>" class="txtbox" checked="checked" onclick="showHide('hide')">

<input type="radio" id="selectemailid" name="emailid" class="txtbox" onclick="showHide('show')"> <input type="text" name="email" id="emailid" class="txtbox" size="30" style="display:none;">

<input type="submit" name="continue" value="Continue" class="txt12" onClick="javascript:valbutton(this.form);">

 

Please how to validate the textbox?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/239258-textbox-validation/
Share on other sites

Yes, it is stored in the database. The first field shows the email address, i have given an option to change the email address. If the end user choose radio button  (others) then it shows a textbox. I want to validate this textbox so that the textbox would not be empty field.

Any idea please....!

Link to comment
https://forums.phpfreaks.com/topic/239258-textbox-validation/#findComment-1229174
Share on other sites

to put this very basically, you will want to direct you form action to a php page, then on that page you will grab your text box field

$email = $_POST['email'];
$submit = $_POST['continue'];

then check is your submit button has been clicked, and if the textbox has been filled out.

if(isset($submit))
{
   if(!empty($email))
   {
      //proceed from here
   }
}

from here you can filter the user input, etc...

Link to comment
https://forums.phpfreaks.com/topic/239258-textbox-validation/#findComment-1229202
Share on other sites

Is it possible to validate in javascript? if it is yes, how?

yes, however part of validation is filtering user information, which can be done in JS but is not recommended. Since javascript can be disabled via browser settings, which disables your validation and allows the user to pass any information that he/she wants and exploits your script to SQL injection...i strongly recommend using php to validate all user input

Link to comment
https://forums.phpfreaks.com/topic/239258-textbox-validation/#findComment-1229501
Share on other sites

The best validation strategy is to use JavaScript for responsiveness and to give the user feedback immediately, while using the back end language (likely PHP in this case) for security.  That said, yes, you can use JavaScript to validate a textarea and stop a form from submitting it the textarea doesn't include any text.  Just realize that this validation does nothing to secure your site.  It's simply a user interface nicety.

 

My JavaScript is a bit rusty, but try something along these lines:

 

var form = document.forms["myForm"]; // substitute 'myForm' with whatever your form name actually is

form.onsubmit = function() {
   var re = /.+/;
   var textExists = re.match(this.elements["textarea"].value); // replace 'textarea' with whatever your textarea's name actually is

   if(!textExists) {
      // highlight the textarea?
      return false;
   }
}

Link to comment
https://forums.phpfreaks.com/topic/239258-textbox-validation/#findComment-1229520
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.