Total members 11894 |It is currently Sat Nov 23, 2024 5:07 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Clear HTML form input fields using JQuery but each one alone.
javascript code
<html>
<head>
<title>Clear specific form fields using JQuery</title>

<!--
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
Note you can download the JQuery package instead of using Google version. -->
<script src="jquery-1.8.3.js"></script>
<style type="text/css">
body
{
background:#F6751E;
font-size:22px;
}

</style>

<script>

function clear_form_elements(HTMLid) {
// find based on html element type.

var inputElement =$(HTMLid);
if(inputElement.is(":input"))
{
if(inputElement.attr('type')!='checkbox'&&inputElement.attr('type')!='radio')
{
inputElement.val('');
}
else{
inputElement.attr('checked', false);
}
}
}


</script>
</script>
</head>
<body>


<b>Reset Each Element freely :</b><br/>

<form action="#" method="GET">

<b> Full Name:</b><input type="text" name="FullName" id="FullNameID" />
<input onclick="javascript:clear_form_elements('#FullNameID')" type="button" value="Clear" />
<br/>
<b> Bio: </b> <textarea rows="6" cols="14" id="BioID" ></textarea>
<input onclick="clear_form_elements('#BioID')" type="button" value="Clear" />
<br/>

<b> CV: </b><textarea rows="6" cols="14" id="CV" ></textarea>
<input onclick="clear_form_elements('#CV')" type="button" value="Clear" /><br/>
<b> Do you agree on policy </b>
<input type="checkbox" name="checkbox" id="checkboxID" />
<input onclick="javascript:clear_form_elements('#checkboxID')" type="button" value="Clear" />

</form>


</body>
</html>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Clear specific form fields using JQuery
 Disable submit button until all form's fields are filled     -  
 Get values of Form parameters using JQuery     -  
 Specific Colors for Specific Forum     -  
 Listing All Rows and Fields in a Table     -  
 How to save a search fields...in Struts2.0     -  
 Exception is not clear     -  
 MATLAB clear memory     -  
 usage of <br> tag clear attribute     -  
 Clear all non alphabetical figures in a String     -  
 php login form (sign-in form)     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com