Below is the jquery and the two code lines one for the text box and the other for the submit button but i just cant get them to link. I have tried a few different ways suggested on here but i cannot get the submit button to link to the text box and clear it. All help greatly appreciated
$j
is set as noConflict()
$j('.submit').keypress(function(){
$j('.comment').val('');
});
<textarea name="name" rows="5" class="fullinput" id="comment"></textarea>
<input id="submit" type="submit" value="Add to List" class="add" />
UPDATE - So i realised that i was using the incorrect selectors the correct code should have been.
$j('#submit').click(function(event){
$j('#comment').val('');
event.preventDefault();
});
This along with the answers below resolved this issue.
This should work:
$j('#submit').click(function(event){
$j('#comment').val('');
event.preventDefault();
});
By clicking on a "submit" input, the user is invoking a postback. Therefore you need to use the built-in javascript event to prevent the postback from happening using the .preventDefault() method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.