Reputation: 1024
In my html form I have a javascript functionality which increment html form row. But somehow it's return error in console log :
Here is the error message : Uncaught SyntaxError: Unexpected token ILLEGAL
Here is the js code I am using :
// add more email number
$(document).ready(function() {
var max_fields = 4; //maximum input boxes allowed
var wrapper = $("#emailWraper"); //Fields wrapper
var add_button = $("#addMoreEmail"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e) { //on add input button click
e.preventDefault();
if (x < max_fields) { //max input box allowed
x++; //text box increment
<?php $sql = mysqli_query($link, 'SELECT * FROM contact_type'); ?>
$(wrapper).append("<tr id='deleteEmail'><td align='right' style='padding-right:10px;'><select name='phoneExt[]'><option value=''>--select--</option><?php while($result_ctype = mysqli_fetch_array($sql)){ $ctid = (int) $result_ctype['ctid']; $all_Contact_type = inputvalid($result_ctype['contact_type']); echo " < option value = $ctid > "; echo $all_Contact_type; echo '</option>';}?></select></td><td align='right'><input type='text' name='' class='small3' id='' placeholder='Value'/><a href='#' class='remove_field'> X</a></td></tr>"); //add input box*/
}
});
$(wrapper).on("click", ".remove_field", function(e) { //user click on remove text
e.preventDefault();
$("#deleteEmail").remove();
x--;
})
});
can you tell me why it's showing in my code ?
Update: Html Code :
<table width="290" border="0" cellpadding="0" cellspacing="0" id="emailWraper">
<tr><td>Email <a href="#" id="addMoreEmail">( + )</a></td><td> </td></tr>
<tr>
<td align="right">Work :</td>
<td id="mailto" align="right"><input value="<?php echo $email; ?>" type="text" name="email"
id="email" placeholder="work email"/></td>
</tr>
<tr>
<td align="right">Private :</td>
<td align="right"><input value="<?php echo $email_private; ?>" type="text" name="email_private" id="email_private" placeholder="private email"/></td>
</tr>
</table>
Upvotes: 0
Views: 2362
Reputation: 5947
Check whether your code has some illegal chacters like white spaces, nulls etc.,
Check here for more answers.
Some users suggest that deleting the last line of the code and adding it again is fixing this issue.
Upvotes: 1