954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to reset text field of my codes?

Could someone fixed this codes, i want the value inside the text fields will empty after submit the form..

huhu...:?:

<script type="text/javascript">
$(document).ready( function() {
$('#submit_id').click(function(){
	doUpload();
	});
	$('#uploadprogress').hide();
});


function doUpload()
{
	// STEP 2. Create the iframe object
	var iframe;
	try {
		iframe = document.createElement('<iframe name="uploadiframe">');
	} 
	catch (ex) {
		iframe = document.createElement('iframe');
		iframe.name='uploadiframe';
}

iframe.src = 'javascript:false';
iframe.id = 'uploadiframe';
iframe.className ='iframe';
document.body.appendChild(iframe);

// STEP 3. Redirect the form to iframe
$('#form').attr('target','uploadiframe');

// STEP 4. Display the progress layer
$('#uploadform').hide();
$('#uploadprogress').show();
$('#uploadiframe').hide();

// .STEP 5. Intercept the upload result
$('#uploadiframe').load(function () {
	$('#uploadprogress').hide();
	$('#uploadform').show();

	// STEP 6. Inform the user about the result
	var result = $('body', this.contentWindow.document).html();
	if(result == 1){
		$('#result1').html('<font color="#060">Successful :)</font>');
	}
	else{
		$('#result1').html('<font color="#060">Successful :)</font>');
	}

	// STEP 7. Destroy the iframe
	setTimeout(function () {
		$('#uploadiframe').remove(); 
		}, 50);
	});
}

</script>

<form name="execute" action="Comment_System/contactajax.php" method="post" style="padding:30px; text-align:center;" onSubmit="return validateContactForm(this);" id="form">
    <input type="text" name="name" id="name" placeholder="Name" title="Enter your name, fullname is better">
    <input type="text" name="email" id="email" placeholder="Email Address" title="Enter your email address" >
    <input type="text" name="subject" id="subject" placeholder="Subject" title="Enter the Subject (Header) of your message" >
    <textarea name="message" id="message" placeholder="Message" title="Enter your message here (use as many space as you want)" ></textarea>
    <input type="text" id="answer_contact" name="answer_contact" placeholder="Answer this, 3 + 7 = ?" title="Answer this simple question" >
    <input type="submit" id="submit_id" class="submit_id" value="Submit" style="text-align:center;" title="Submit your message" >
    
<p><div id = "uploadprogress">
	<img src="loader.gif"/>
</div></p>

<span id="result1"></span>

</form>
dean8710
Junior Poster in Training
54 posts since Jul 2011
Reputation Points: 7
Solved Threads: 2
 

You should be able to do the following in the click event for the submit_id button:

$('input[type=text]').val('');
stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

like this?

$(document).ready( function() {
$('#submit_id').click(function(){
	doUpload();
	});
	$('#uploadprogress').hide();
        $('input[type=text]').val('');
});
dean8710
Junior Poster in Training
54 posts since Jul 2011
Reputation Points: 7
Solved Threads: 2
 

No, since it's not in the click event.

stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

yes, its not function, then where it should be?

dean8710
Junior Poster in Training
54 posts since Jul 2011
Reputation Points: 7
Solved Threads: 2
 

Please, just put it inside the click event of the submit_id button and see what happens.

$('#submit_id').click(function(){
    doUpload();
    $('input[type=text]').val('');
});
stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

if that, the value in the fields will be empty first so, no data will be submited.

i changed it to:

// STEP 6. Inform the user about the result
	var result = $('body', this.contentWindow.document).html();
	if(result == 1){
		$('#result1').html('<font color="#060">Successful :)</font>');
        //clear fields after submit
        $('input[type=text]').val('');
	}
	else{
		$('#result1').html('<font color="#060">Successful :)</font>');
        $('input[type=text]').val('');
	}


and it fixed. and now, i want to know how to clear textarea because:$('input[type=textarea]').val('');

not empty the textarae..

please share with me the code..

dean8710
Junior Poster in Training
54 posts since Jul 2011
Reputation Points: 7
Solved Threads: 2
 
if that, the value in the fields will be empty first so, no data will be submited.

Um ... ok, I guess your submit button isn't actually submitting then and you've got some weird logic going on.

As for the next question, I'll give you a hint, it's a textarea, not an input.

stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: