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" ><br />
    <input type="submit" id="submit_id" class="submit_id" value="Submit" style="text-align:center;" title="Submit your message" ><br />
    
<p><div id = "uploadprogress">
	<img src="loader.gif"/>
</div></p>

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

</form>

Recommended Answers

All 7 Replies

Member Avatar for stbuchok

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

$('input[type=text]').val('');

like this?

$(document).ready( function() {
$('#submit_id').click(function(){
	doUpload();
	});
	$('#uploadprogress').hide();
        $('input[type=text]').val('');
});
Member Avatar for stbuchok

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

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

Member Avatar for stbuchok

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('');
});

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..

Member Avatar for stbuchok

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.